Thursday, October 31, 2013

Regex to remove version information from RPM strings

Overview

Removing version strings helps compare packages between two installations using simple diff/winmerge like tools.
Later using unix commands such as 'comm' we can obtain just what is unique in one install and patch the other install.

The Regex

The following regex works within vim/vi editors:

-[-0-9]\+\.[-0-9A-z\.]*\.

Effect of using the regex is as shown below:


Note the highlighted strings.

Effect of using a global replace is as shown below:

VI/VIM global search and replace with a single 'dot':

:g/-[-0-9]\+\.[-0-9A-z\.]*\./s//\.

Replaced result:



Using 'comm' to generate unique packages from one or the other system:

  • Sort both the files that you wish to diff.
    The following command will sort the file in-place


    sort -o vm1rpm.txt vm1rpm.txt
  • Run the comm command as below:
    comm -23 vm1rpm.txt vm2.rpm.txt
This will generate a list of only what is in vm1rpm.txt (I am not providing output as it is reasonably obvious).