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

How about this solution, files system_1 and system_2 contain output of rpm -qa like this:

$ 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:

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):

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.