![]() |
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 |
| compare two files for matching in solaris | amir07 | Shell Programming and Scripting | 8 | 01-02-2009 06:40 PM |
| Compare two files and remove all the contents of one file from another | royalibrahim | Shell Programming and Scripting | 3 | 11-18-2008 12:55 AM |
| compare files by lines and columns | giviut | Shell Programming and Scripting | 4 | 01-17-2008 06:00 AM |
| Trying to compare lines in 2 files | brdholman | Shell Programming and Scripting | 2 | 09-20-2007 07:46 AM |
| Find matching lines between 2 files | jojojmac5 | UNIX for Dummies Questions & Answers | 5 | 01-18-2007 01:06 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Code:
awk '{arr[$0]++} END {for (i in arr) {if (arr[i]>1) {print $0} }} ' file1 file2 > dupfile
awk 'FILENAME=="dupfile" {arr[$0]++}
FILENAME=="file1" {if ($0 in arr) {next} else {print $0 >"newfile1"}}
FILENAME=="file2" {if ($0 in arr) {next} else {print $0 >"newfile2"} }' dupfile file1 file2
|
|
||||
|
Try this...
Code:
awk '{ if (FNR==NR) {arr[$0]++;next}
if ($0 in arr) { arr[$0]--; if (arr[$0] == 0) delete arr[$0]; next}
{print $0 >"newfile2"} }
END {for (i in arr) {print i >"newfile1"} } ' file1 file2
Last edited by King Kalyan; 06-19-2009 at 04:06 PM.. Reason: Corrected the code for duplicates also... |
|
||||
|
I also have this kind of problem. The code above deletes the lines which are alike on the two files. How can i do this, on a separate file?
File 3: #from first file a3px lm4 xpm 0wmp jga1 wmp6 #from second file a3px lm4 xpj 0xmp lm4 xpm thanks a lot! |
![]() |
| Bookmarks |
| Tags |
| file comparison |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|