|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
how to display the unique strings in two files using shell script or commands. I tried diff and cmp but it shows the entire line, i need only the mismatched strings. File1: Code:
sat,sun,mon,tue rose,lilly,lotus white,red,blue,green,pink File2: Code:
sat,sun,mon,tue rose,sunflower,lotus white,red,blue,green,pink output: Code:
something like this. lilly (line 2, 2nd column) in file1 doesnt match with file2. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Try sth like this.. Code:
awk -F, 'NR==FNR{for(i=1;i<=NF;i++){A[i,FNR]=$i};next}{for(i=1;i<=NF;i++){if(A[i,FNR]!=$i){print A[i,FNR],"(line "FNR","i" Column) in file1 does not match with file2";}}}' file1 file2 |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Pamu: Its throwing error.. Code:
bash-3.00$ awk -F, 'NR==FNR{for(i=1;i<=NF;i++){A[i,FNR]=$i};next}{for(i=1;i<=NF;i++){if(A[i,FNR]!=$i){print A[i,FNR],"(line "FNR","i" Column) in file1 does not match with file2";}}}' file1.txt file2.txt
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1 |
|
#4
|
|||
|
|||
|
Use
/usr/xpg4/bin/awk or
nawk on Solaris.
|
| The Following User Says Thank You to pamu For This Useful Post: | ||
Arun_Linux (02-14-2013) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Many thanks... It works perfectly... tested on both solaris and linux :-).
|
| Sponsored Links | ||
|
![]() |
| Tags |
| compare tools |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Finding a text in files & replacing it with unique strings | gordom | Shell Programming and Scripting | 5 | 01-28-2013 08:35 AM |
| calculating unique strings values | Paulwintech | Shell Programming and Scripting | 9 | 02-15-2012 02:54 PM |
| Script that sorts and show only unique IP | linuxgeek | Shell Programming and Scripting | 6 | 06-17-2010 03:00 AM |
| How to count unique strings | my_Perl | Shell Programming and Scripting | 6 | 07-31-2009 04:28 AM |
| Finding Unique strings which match pattern | tektips | UNIX for Dummies Questions & Answers | 5 | 02-16-2009 04:13 PM |
|
|