![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| How to compare 2 files. | ashoka123 | Shell Programming and Scripting | 6 | 10-21-2008 02:38 AM |
| need to compare two files | sriu76 | UNIX for Dummies Questions & Answers | 1 | 09-25-2008 05:57 AM |
| compare files | danabo | Shell Programming and Scripting | 3 | 05-19-2008 12:09 PM |
| compare files | spt | Shell Programming and Scripting | 1 | 05-09-2008 10:57 AM |
| help! need to compare files | danielsf | Shell Programming and Scripting | 6 | 07-09-2003 05:09 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
awk NR==FNR compare 2 files produce a 3rd
hi, i have two files, both with 3 columns, the 3rd column has common values between the two files and i want to produce a 3rd file with 4 columns.
file 1 a, ,b c file 2 a, b ,d I want to compare the 3rd value and if a match print to file 3 with the 3 columns from the first file plus the entitlement column from file 2 added as 4th column , delimited. file 3 a, b, c, d I have been trying things like this borrowed off other posts but its outputing completely wrong, ive never really used awk that much awk 'NR==FNR{x[$3]=$2;next}$3 in x&&$2=x[$3]' OFS="," FS="," file2 file1 Last edited by borderblaster; 03-18-2009 at 09:04 AM.. |
|
||||
|
When I run this I get a syntax error, I only have awk on the server as well
awk -F, '{ if ( FILENAME == "file1.txt" )_[$3]=$0 else _[$3]=_[$3]","$1 }END { for ( i in _ ) print _[i] }' file1.txt file2.txt awk: cmd. line:1: { if ( FILENAME == "file.txt" )_[$3]=$0 else _[$3]=_[$3]","$1 }END { for ( i in _ ) print _[i] } awk: cmd. line:1: ^ syntax error |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|