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?
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.
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.
Summary: Hi All, I've 2 files a.c and b.c How can I find which one is newer(datetime) among them using either batch file OR at command line Thanks, Srini ...
Summary: hello, i have 2 text files, one is small (file_1: about 200 lines) and the other is fairly large (file2: 12 k - 20 k lines). file_1: tango 12 beta 256 alpha 1700 tango 1200 file_2: tango 12 tango 125 ...
Summary: Hi Razor, Thank you very much for ur solution. I create the output file with (.csv) extension. Good idea.. Can you tell me how to send this file to our team as attachment mail. I used the below comma...