Computing.Net > Forums > Programming > How to compare 2 files using awk?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

How to compare 2 files using awk?

Reply to Message Icon

Name: vinodjadye
Date: July 27, 2007 at 07:41:38 Pacific
OS: Linux
CPU/Ram: Intel
Product: Dell
Comment:

Hi,
I need to compare 2 files using awk, file1 & file2 line by line. Field 5 in everyline of file1 should be compared in whole file2 & if match is found then print that line in file2 & then print next 20 lines in file2. Continue the same process for all lines in file1. Can some one try this & send the script to me at the earliest.
Thx.


Vinod



Sponsored Link
Ads by Google

Response Number 1
Name: user57
Date: July 30, 2007 at 03:05:28 Pacific
Reply:

Try something like this...

awk -F: 'NR==FNR {a[$5]; next}

{
$5 in a
print $0
getline

for(i=1;i<=20;i++) {
print
getline
}
}' f1 f2


0

Response Number 2
Name: vinodjadye
Date: July 30, 2007 at 15:34:31 Pacific
Reply:

Can you provide your email ID?
I will provide you 2 files..you can test your code and then send that to me. I am novice on awk & Every time i run suggested code, i am not getting any o/p.

Vinod


0

Response Number 3
Name: vinodjadye
Date: July 30, 2007 at 16:12:58 Pacific
Reply:

after trying the code written above, i am getting all lines in test2 as output.

>./test.awk test1 test2

Vinod


0
Reply to Message Icon

Related Posts

See More


Dos box problems simple program



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: How to compare 2 files using awk?

How to compare 2 file date time stamps in bat www.computing.net/answers/programming/how-to-compare-2-file-date-time-stamps-in-bat/19411.html

how to compare 2 files in java www.computing.net/answers/programming/how-to-compare-2-files-in-java/19445.html

How to create xls file using shell www.computing.net/answers/programming/how-to-create-xls-file-using-shell-/18530.html