![]() |
|
|
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 |
| Print values of a string froma file | ayhanne | UNIX for Dummies Questions & Answers | 2 | 01-28-2009 09:10 PM |
| how to print the values of pcpu of any process in unix | ronit_ok2000 | UNIX for Dummies Questions & Answers | 2 | 11-13-2008 07:00 AM |
| Awk to print distinct col values | anduzzi | Shell Programming and Scripting | 22 | 08-18-2008 06:09 PM |
| Print column names along with values from SQL | thana | Shell Programming and Scripting | 5 | 07-24-2008 03:33 AM |
| awk to print mon and max values of ranges | Mudshark | Shell Programming and Scripting | 3 | 02-02-2006 03:06 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to print Dissimilar keys and their values?
Hi guyz I have been using this script to find similar keys in 2 files and merge the keys along with their values. Therefore it prints similar keys by leaving dissimilar. Any one knows how to print only Dissimilar leaving Similar.
Help would be appreciated. The script I'm using for similar ones is awk 'FNR==NR{ a[$1]=$0;next}a[$1]!=""{print $1,a[$1]}' file2 file1 the files for the script for similarkeys is Mac1-/home/>file1 1234 133 1345 134 23 4555 Mac1-/home/>file2 1234 tab kshgjkghj 100 tab dfghjk 23 tab drjghfg 134 tab drkhgjgj 1345 tab djghf 4555 tab khdjhgjfg 13tabjghhdgf Mac1-/home/l>output 1234 1234 tab kshgjkghj 1345 1345 tab djghf 134 134 tab drkhgjgj 23 23 tab drjghfg 4555 4555 tab khdjhgjfg The script I' trying to design has to do some thing like thisvfor dissimilar ones Mac1-/home/l>output 100 tab dfghjk 13 tab jghhdgf |
|
||||
|
Code:
awk 'BEGIN { while (getline < "q1.txt") data[$1]=1 } { if (data[$1]) print $1 "\t" $0; else print "\t" $0 }' q2.txt
-----Post Update----- X:thu gireeshkumarbogu$ cat q1.txt a9 abc a1 def a2 ghi a4 poiu X:thu gireeshkumarbogu$ cat q2.txt a1 def a2 ghi a6 ghij X:thu gireeshkumarbogu$ awk 'BEGIN { while (getline < "q1.txt") data[$1]=1 } { if (data[$1]) print $1 "\t" $0; else print "\t" $0 }' q2.txt a1 a1 def a2 a2 ghi a6 ghij X:thu gireeshkumarbogu$ awk 'BEGIN { while (getline < "q1.txt") data[$1]=1 } { if (data[$1]) print $1 "\t" $0; else print "\t" $0 }' q2.txt -----Post Update----- X:thu gireeshkumarbogu$ cat q1.txt a9 abc a1 def a2 ghi a4 poiu X:thu gireeshkumarbogu$ cat q2.txt a1 def a2 ghi a6 ghij X:thu gireeshkumarbogu$ awk 'BEGIN { while (getline < "q1.txt") data[$1]=1 } { if (data[$1]) print $1 "\t" $0; else print "\t" $0 }' q2.txt a1 a1 def a2 a2 ghi a6 ghij X:thu gireeshkumarbogu$ awk 'BEGIN { while (getline < "q1.txt") data[$1]=1 } { if (data[$1]) print $1 "\t" $0; else print "\t" $0 }' q2.txt Last edited by repinementer; 05-28-2009 at 05:32 AM.. Reason: added code tags |
|
||||
|
Quote:
Experiment with the second awk statement. You just need to invert ($1 in a) part. Give it a shot. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|