Have an account? Sign in
Login  Register  Facebook
Comparing two files in Unix
Hello everybody,
I dropped in to find an excellent reply for a Unix query asked by an user. I hope i will also get some help here.The following is the scenario

I have got 2 files which have got n number of lines.
eg: File 1
465466454
546545454
5454454
Data=4545454545484848484
kuh  uytyer huihkuh 
File 2
e4654sdfdsf
544hjklhjl
464jku
Data=4545454545484848484
kuh  uytyer huihkuh 

As you can see both files have got the same data after the place "Data=" (this "Data=" occurs only once in the file)

So i need to cut the lines that are before the "=" sign and then compare these two files and then get an output stating if these 2 files are equal in a csv format file.

Its not just one file but it will be many files in 2 different folders and every first file in one folder needs to be compared with the first file in the another folder and so on..

Kindly help me in getting this code.
Started: September 19, 2011 Latest Activity: June 2, 2018 comparef
5 Answers
Propecia Mail Order Viagra Levitra O Cialis <a href=http://cialicheap.com>cialis</a> Abortion Pill Online How Much Is Cialis Without Insurance Cialis Basso Prezzo

Posted: Ellgaibra
In: June 2, 2018

I think you should clarify your question. The answers so far suggest to use awk to get the string after the'='. However, as far as I understand your question, you want to look at all lines from the beginning until the line that starts with 'Data='.

You could use
sed '/^Data=/,$d' file
to delete all lines from the first line that matches '^Data=' to the end and feed the result into diff using the syntax that janmoesen mentioned, e.g.
diff <(sed '/^Data=/,$d' file1) <(sed '/Data=/,$d' file2)

Posted: MacOS
In: September 19, 2011

this is how you use awk to get the data after the "=" sign
awk '/Data=/{gsub("Data=","");f=1}f' file > temp1
that is being redirected to a temp file. do the same for file 2 that you are comparing. Then use the command diff to compare the files.

Posted: Go
In: September 19, 2011

You can use the unix tool awk to get the data after the "=" and then use diff to compare it.

Posted: xtremex
In: September 19, 2011

Do you know how many lines you have before the "=" sign? (ie: for 2 given files, are "n" equals or not?) Because you could use -A option for grep.

Posted: MacOS
In: September 19, 2011

Hi we cant tell the number of lines that are before the = sign . I am just a Functional Guy with no knowledge in coding especially Unix.. could you please help me with a complete coding?
September 19, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer