Compare two files containing package names and version number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare two files containing package names and version number
# 1  
Old 06-22-2014
Compare two files containing package names and version number

I have 2 files each containing a list of same fedora packages but with different version number. I want to compare the 2 files and remove the lines containing a newer or older version number
# 2  
Old 06-22-2014
How about this solution, files system_1 and system_2 contain output of rpm -qa like this:

Code:
$ head -3 system_1
gnome-vfs2-smb-2.24.2-6.el6.x86_64
perl-XML-Parser-2.36-7.el6.x86_64
gnome-python2-desktop-2.28.0-5.el6.x86_64

$ head -3 system_2
hplip-libs-3.13.11-4.fc20.x86_64
gnu-free-fonts-common-20120503-8.fc20.noarch
GConf2-3.2.6-7.fc20.x86_64

In the below script specify the following in OPTS:

Code:
A - Package is Additional in file1
M - Package is Missing in file1
N - Version is Newer in file1
O - Version is Older in file1
S - Version is the Same in file1 and file2
D - Debug print version numbers with package names

And here is your code (options used here are Debug plus Newer and Additional in file1):

Code:
awk -v OPT=DNA '
FNR==1{sys++}
{
   match($0,"-[0-9]")
   pkg=substr($0,1,RSTART-1)
   ver=substr($0,RSTART+1)
   if (sys==1) {
      PKGS[pkg]=ver
      next
   }
   if(!(pkg in PKGS)) {
      if(index(OPT, "M")) print "M:" pkg (index(OPT, "D") ? "(" ver ")":"")
      next
   }
   if (index(OPT, "D")) debug="(" PKGS[pkg] " vrs " ver ")"
   if (index(OPT, "N") && PKGS[pkg] > ver) print "N:" pkg debug
   if (index(OPT, "O") && PKGS[pkg] < ver) print "O:" pkg debug
   if (index(OPT, "S") && PKGS[pkg] == ver) print "S:" pkg debug
   delete PKGS[pkg]
}
END {
   if (index(OPT, "A")) for(pkg in PKGS) print "A:" pkg (index(OPT, "D") ? "(" PKGS[pkg] ")":"")
}' system_1 system_2

Output is <Type>:<package> , where <Type> is single letter from "NOMAS" and <package> is package name plus optional debug info.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare files with different names in different directories

Hi, I have a requirement to compare files in different directories with different names. The files have a datestamp in their name (It might not be a sequential datetimestamp). This is for Redhat Linux. I have more than 5 directories and more than 10 file in each directory to be compared. ... (4 Replies)
Discussion started by: GosarJunk
4 Replies

2. Shell Programming and Scripting

Compare two files and get only missing names

I need to compare two files (oldfile1 & newfile). Need to ignore the values which are present in both files. At the same time, i need to get only records in new file. Tried using Join -v1 -v2 oldfile1 newfile (suspect it has not worked as expected). could anyone of you please help me here. (5 Replies)
Discussion started by: Selva_2507
5 Replies

3. Shell Programming and Scripting

Compare two files, then outputs line number

I have two files, "ranked.txt" and "sorted.txt". Sorted.txt is a smaller subset from ranked.txt that is sorted in alpha order. However ranked.txt preserves the ranking of words I would like to keep. How do I check the rank of every word in sorted.txt when matched to the original ranked.txt? I... (8 Replies)
Discussion started by: pxalpine
8 Replies

4. Shell Programming and Scripting

Check for particular files and compare the file names

Hi, Below are the 2 files in directory /tmp: masterCSF242323.img indexCSF242323.img 1) I want to compare if both the number (242323) are same in both the files. If they are same print - Files matching, else print files do not match. 2) Also if only index file is present in that... (7 Replies)
Discussion started by: apatil65
7 Replies

5. UNIX for Dummies Questions & Answers

how to compare names of files?

hi, can somebody tell me how to compare names of files? the situation is I have 2 files file1 and file2 and I want to figure out which file has the biggest ending, in this case file2 is. thank you (3 Replies)
Discussion started by: s3270226
3 Replies

6. Shell Programming and Scripting

Compare list [ names and size files ]

Hello, I've downloaded a huge amont of files I've got a list of files from a remote server. -rw-r--r-- 1 str661 strem 453465260 Dec 16 15:54 SATRYS2V1_20021218_temp_bias.nc -rw-r--r-- 1 str661 strem 17669468 Dec 16 18:01 SATRYS2V1_20021225_hdyn_bias.nc -rw-r--r-- 1... (9 Replies)
Discussion started by: Aswex
9 Replies

7. UNIX for Dummies Questions & Answers

Substract a certain number to the names of several files

We have a list of files (raw and jpeg types) with 2 different extensions (rw2 and jpg). When there is both the raw and jpeg files, their file numbers must be the same (215 and 215, 218 and 218). Sometimes there is only the jpeg file (216,217). bla_215.rw2 bla_215.jpg bla_216.jpg bla_217.jpg... (9 Replies)
Discussion started by: Epictete
9 Replies

8. Shell Programming and Scripting

Script to Compare a large number of files.

I have a large Filesystem on an AIX server and another one on a Red Hat box. I have syncd the two filesystems using rsysnc. What Im looking for is a script that would compare to the two filesystems to make sure the bits match up and the number of files match up. its around 2.8 million... (5 Replies)
Discussion started by: zippdawg2001
5 Replies

9. Shell Programming and Scripting

Finding files with names that have a real number greater then difined.

I am trying to find all files in a directory whose name has a real number larger then the number I am looking for. For example: . |-- delta.1.5.sql |-- delta.2.1.sql |-- delta.2.2.sql |-- delta.2.3.sql |-- delta.2.4.sql `-- delta.2.5.sql I know my database is at 2.2 so I want an... (2 Replies)
Discussion started by: harmonwood
2 Replies

10. UNIX for Dummies Questions & Answers

total number of files which have "aaa" in files whose names are File*_bbb*

I am getting the list of all the files which have "aaa" from files whose name is File*_bbb*. grep -l "aaa" File*_bbb* But I want to count the number of files. That is I want the total number of files which have "aaa" in files File*_bbb* If I run the following for getting number of... (1 Reply)
Discussion started by: sudheshnaiyer
1 Replies
Login or Register to Ask a Question