![]() |
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 |
| Combining two files | hemangjani | Shell Programming and Scripting | 7 | 06-13-2007 10:32 PM |
| Combining Two Files | stevefox | Shell Programming and Scripting | 4 | 02-20-2006 05:09 AM |
| Combining Two Files | bat711 | Shell Programming and Scripting | 3 | 10-05-2005 01:26 PM |
| Combining files | Enda Martin | UNIX for Dummies Questions & Answers | 2 | 07-20-2001 10:31 AM |
| combining files | apalex | UNIX for Dummies Questions & Answers | 3 | 06-19-2001 09:49 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Matching and combining two files
Hi, How can I match the first two fields of file2 against the first two fields of file1 and where they match combine the two lines. If the name
(example-Aidan Rielly) is in file1 but not in file2 then just write the info from file1 to the combined output file. If the name (example-Silvia Spoelstra) is in file2, but not in file1, then do not write it to the combined output file. file1 Firstname,Surename,City Aidan,Rielly,Derry John,Doe,London Jack,Daniles,Glasgow Ivor,Engine,Cardif file2 Firstname,Surname,Country,ISO Jack,Daniels,Scotland,GB John,Doe,England,UK Ivor,Engine,Wales,UK Silvia,Spoelstra,Germany,DE Combined file Firstname,Surename,City,Country,ISO Aidan,Rielly,Derry John,Doe,London,England,UK Jack,Daniles,Glasgow,Scotland,GB Ivor,Engine,Cardif,Wales,UK thanks in advance Pete Last edited by p3t3r; 05-20-2008 at 07:04 AM.. |
|
||||
|
Hi, thanks for the quick response. I get a syntax error when I try this.
$ awk -F, ' > BEGIN{print "Firstname,Surename,City,Country,ISO"} > NR==FNR{a[$1$2]=$3","$4;next} > a[$1$2]{print $0 ","a[$1$2];next}1 > ' file2 file1 awk: syntax error near line 4 awk: bailing out near line 4 any idea ? Pete |
|
||||
|
A common problem is that there are different versions of awk. You probably have the original "One True" awk; see if you can find nawk or mawk or gawk on your system. Also on Sun and HP-UX look for the XPG4 version.
|
![]() |
| Bookmarks |
| Tags |
| solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|