![]() |
|
|
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 |
| Remove spaces from first field, and write entire contents into other text file | carriehoff | Shell Programming and Scripting | 3 | 11-11-2008 02:45 PM |
| Compare & replace contents within a file | kaustubh137 | Shell Programming and Scripting | 2 | 05-27-2008 07:56 AM |
| compare array contents with file | orahi001 | UNIX for Dummies Questions & Answers | 0 | 03-25-2008 05:44 PM |
| Query:just need to remove the contents of the file without deleting that | namishtiwari | Shell Programming and Scripting | 3 | 02-04-2008 05:41 AM |
| remove the contents of a file | surjyap | SUN Solaris | 2 | 03-02-2006 04:02 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Compare two files and remove all the contents of one file from another
Hi, I have two files, in which the second file has exactly the same contents of the first file with some additional records. Now, if I want to remove those matching lines from file2 and print only the extra contents which the first file does not have, I could use the below unsophisticated command, consider f1 and f2 are the two files Code:
var=`cat f1` grep -v "$var" f2 but I need a more optimal solution with fast and reliable with less memory consumption. I have found these 2 lines of code, but it does not work for files having lengthier lines: Code:
fgrep -v -x -f f2 f1
awk 'NR==FNR {b[$0]; next} !($0 in b)' f2 f1
Last edited by royalibrahim; 11-18-2008 at 12:51 AM.. |
|
||||
|
Thanks to you all for the suggestions. But anyone has any awk, perl code to do this task? And Also, the below perl code will remove duplicate, non-consecutive lines based on the last field without sorting. Now, please tell me, what should I change in this code in order to print unique lines of a file by just not seeing the last field but the entire line (the whole record)? Code:
perl -ane'print unless $_{$F[-1]}++'
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|