![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| merging text files | code19 | Shell Programming and Scripting | 8 | 02-13-2008 05:13 AM |
| Merging two files | venommaker | UNIX for Dummies Questions & Answers | 4 | 01-10-2008 05:15 AM |
| merging INPUT and files | fiol73 | UNIX for Dummies Questions & Answers | 1 | 01-01-2007 02:14 PM |
| merging two files based on some key | Vandana Yadav | Shell Programming and Scripting | 1 | 02-03-2006 06:45 AM |
| merging two files | rameshonline | Shell Programming and Scripting | 13 | 06-29-2004 03:06 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
merging of 2 files AWK - part 2
i have try , but i think i will never learn awk
now i have 2 files : a 1:aaa:2:aaa1 2:bbb:2:bbb1 3:ccc:3:ccc1 b aaa:2 bbb:0 ccc:3 output: for all lines where a.$2 == b.$1 i want to compare a.$3 != b.$2 if true then set err=1 if false set err=0 and print all lines from file a + err Thanks & regards Peter |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
what other languages do you know..? there's no restriction for you if you don't like awk. you can do what you want in most other languages. The standard algo is the same.
1) open file1 2) read a line 3) split the components and get the ones you need to compare 4) open file2 5) read the line 6) split the components and get the ones you need to compare to 3) 7) compare 8) display results 9) close the files |
|
#3
|
|||
|
|||
|
awk
Hi,
I think this one should be ok for you! Please try. paste file1 file2 | sed 's/ /:/' > temp awk 'BEGIN{OFS=FS=":"} { if($2==$5) if($3==$6) print $1":"$2":"$3":"$4":"0 else print $1":"$2":"$3":"$4":"1 }' temp |
|||
| Google The UNIX and Linux Forums |