#!/bin/bash

#find duplicate package names
PACKAGES=`rpm --queryformat "%{NAME}-%{VERSION}-%{RELEASE}%%.%{ARCH}\n" \
  -qa|awk  '{ sub("-[^-]*-[^-]*%", "");  print}'|sort|uniq -d`

#find the older package(s) for the duplicates
for package in $PACKAGES; do
  ARCH=`rpm --queryformat "%{ARCH}\n" -q $package|uniq -d`
  rpm -q $package | sort -n |
    awk "{version[NR]=\$0}; END{for(i=1;i<NR;i++) \
      printf \"%s.%s\n\", version[i], \"$ARCH\" }"
done
