Results 1 to 3 of 3
I've got two files. They both contain package names. Is there any way I can go through the package list on one file, and search to see if each package ...
- 04-15-2010 #1Just Joined!
- Join Date
- Nov 2009
- Posts
- 13
Bash query
I've got two files. They both contain package names. Is there any way I can go through the package list on one file, and search to see if each package exists in the other file? What I'd want to do, is if the package name is found in the the main file, then go to the next line. If its not found then print that package name to another file.
I know you can use diff, but it doesn't seem to be that straight forward. As I understand it diff searches line by line, so if line one doesn't match line one in another file, then it prints it out. That's not exactly what I want.
I just really need an easy way to filter out the additional packages that exist on a new server. If I have a list of packages that aren't on the original server, then i can just delete them.
Not sure if I've made any sense but there must be a quicker way to do what i need to. It would take me ages to scan manually through the package names in each list, and highlight the ones i dont need.
- 04-15-2010 #2
What about this:
Code:sort list1 |uniq > sorted_list1 sort list2 |uniq > sorted_list2 diff sorted_list1 sorted_list2
You must always face the curtain with a bow.
- 04-16-2010 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Another method would be:Code:comm [OPTION]... FILE1 FILE2 DESCRIPTION Compare sorted files FILE1 and FILE2 line by line. With no options, produce three-column output. Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files. -- excerpt from man comm, q.v.
note that this will list items that are unique in each file, but your description indicated that one would be a super-set of the other, i.e not of wildly different content.Code:sort file1 file2 | uniq -u
If the files are not too long:
will avoid the sort ... cheers, drlCode:grep -v -f file1 file2
Last edited by drl; 04-16-2010 at 10:37 AM. Reason: ( Edit 1: look for unique items, not duplicates. )
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote