![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| compare files in two directories and output changed files to third directory | bkeep | Shell Programming and Scripting | 4 | 08-26-2009 07:58 AM |
| compare two files and to remove the matching lines on both the files | shellscripter | Shell Programming and Scripting | 4 | 06-20-2009 09:48 AM |
| compare two txt files | space13 | Shell Programming and Scripting | 8 | 09-22-2006 10:40 AM |
| help! need to compare files | danielsf | Shell Programming and Scripting | 6 | 07-09-2003 06:09 PM |
| Compare two files | b5fnpct | UNIX for Dummies Questions & Answers | 2 | 08-16-2001 04:28 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
compare two files using awk
Hi, I want to compare two files using awk and write an output based on if the records matched. Both the files are space delimitted. File A: Code:
8351 00000000000636 2009044 -00001.000 8351 00000000000637 2009044 -00002.000 8351 00000000000638 2009044 -00001.000 8351 00000000000640 2009044 -00003.000 8351 00000000000642 2009044 -00001.000 8351 00000000000650 2009044 -00001.000 File B: Code:
8351 00000000000636 006 8351 00000000000637 002 8351 00000000000642 001 Output: Code:
006 8351 00000000000636 2009044 -00001.000 002 8351 00000000000637 2009044 -00002.000 000 8351 00000000000638 2009044 -00001.000 000 8351 00000000000640 2009044 -00003.000 001 8351 00000000000642 2009044 -00001.000 000 8351 00000000000650 2009044 -00001.000 Basically, if the second column of File A matches with the second column of File B. I need to write the third column of file B and the complete line from File A. If not matched I need to write 000 and then the complete line in File A. I tried some awk commands.. but didnt work. This below code i wrote to get the matched record and write the third column and the file A. But the third column is not getting written. Any help will be much appreciated. Code:
awk '
NR==FNR{a[$2]=$2;next}
a[$2]{print a[$3] $0}' $ZEROSTOCK $INFILE > $INTEMP
Last edited by vgersh99; 11-02-2009 at 04:54 PM.. Reason: code tags, please! |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|