![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | 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. Shell Script Page. |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| compare 2 files.. | amon | Shell Programming and Scripting | 8 | 1 Week Ago 07:34 AM |
| Compare files | kharen11 | UNIX for Advanced & Expert Users | 25 | 03-14-2007 01:35 AM |
| compare two txt files | space13 | Shell Programming and Scripting | 8 | 09-22-2006 06:40 AM |
| compare files and beyond | MizzGail | UNIX for Dummies Questions & Answers | 2 | 04-25-2003 10:34 AM |
| compare files | ingunix | UNIX for Dummies Questions & Answers | 3 | 05-24-2001 08:44 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
compare two files
File1
E100 0 5/29/1993 0 E001 E000 E102 0 1/23/1994 0 E001 E003 E104 0 6/4/1994 0 E001 E003 E105 0 7/30/1993 0 E001 E003 E106 0 1/9/1993 0 E001 E003 E108 0 2/3/1995 0 E001 E003 E109 0 2/15/1995 0 E001 E001 File2 E108 0 2/3/1995 0 E001 E003 E109 0 2/15/1995 0 E001 E001 E110 0 2/15/1995 0 E001 E001 E111 0 9/15/1996 0 E001 E001 E112 0 4/21/1997 0 E001 E001 These are the two files Column 1,2 and 3 are the key fields. A TO B MAPPING I need to compare file1 key columns and the file2 key columns. If File1 key column matches with File2 key column move the entire row of file1 which are matching to > File3. E108 0 2/3/1995 0 E001 E003 E109 0 2/15/1995 0 E001 E001 If the key columns of file1 not matches with file2 then move the entire row of the file1 which are not matching in the file2 > File4. E100 0 5/29/1993 0 E001 E000 E102 0 1/23/1994 0 E001 E003 E104 0 6/4/1994 0 E001 E003 E105 0 7/30/1993 0 E001 E003 E106 0 1/9/1993 0 E001 E003 ///LY B TO A mapping To file5 and file6. Please let me know on this ASAP……… Thanks in advance CHARAN |
| Forum Sponsor | ||
|
|
|
||||
|
Or even:
Code:
awk 'END { for (k in f2) {
split(f2[k], t)
print f2[k] > (((t[1] SUBSEP t[2] SUBSEP t[3]) in f1) ? "file5" : "file6")
}
}
NR == FNR { f2[$1,$2,$3] = $0; next }
{ print > (($1 SUBSEP $2 SUBSEP $3) in f2 ? "file3" : "file4")
f1[$1,$2,$3] = $0 }' file2 file1
|
|
|||
|
Thanks !
It is working when we have 3 key fields. II Step : I want to pass key fields dynamically .....( file may have key fields upto 4,5,6 etc. ) then what changes i have to do for the above ..... Can you plz help me !! |
|||
| Google UNIX.COM |