Computing.Net > Forums > Unix > list of different lines in files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

list of different lines in files

Reply to Message Icon

Name: johnny
Date: July 14, 2003 at 12:59:09 Pacific
OS: unix
CPU/Ram: ?
Comment:

I need help from anyone out there. I have three files (one about 400 lines, one about 13000 lines and one about 13450 lines). The two smaller files are included somewhere within the larger file, however I am trying to isolate the 50 lines that do not appear in either of the first two files.

I've tried a combination of joins and cmps but I can't seem to figure out how to isolate the 50 lines that don't appear in the other two files. Can any of you help?

thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: July 14, 2003 at 14:45:40 Pacific
Reply:

I would think sort and diff should do it:

sort file1 > file1s
sort file2 file3 > file23s
diff file1s file23s |
  grep '^\<' |
  cut -c3-

Or, for this awk solution, file2 and file3 should be the smallest 2 files since they have to fit in a memory array:

awk 'BEGIN{
while ((getline < "file2") > 0)
   list[$0] = 1
while ((getline < "file3") > 0)
   list[$0] = 1}
!list[$0]' file1 > file1.only


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: list of different lines in files

Find length of each line in a file. www.computing.net/answers/unix/find-length-of-each-line-in-a-file/7852.html

remove top line in file www.computing.net/answers/unix/remove-top-line-in-file/4769.html

Read first character of each Line www.computing.net/answers/unix/read-first-character-of-each-line/8088.html