1

i have two files packages32.txt - packages64.txt and now i want the diffrence between files so i think delete the versions is better way.

sys-libs/libseccomp-2.1.1
sys-libs/libunwind-1.1
sys-libs/libutempter-1.1.6-r1
sys-libs/mtdev-1.1.5
sys-libs/ncurses-6.0-r1
sys-power/upower-0.99.2-r1
sys-process/cronbase-0.3.3
sys-process/htop-1.0.3
sys-process/lsof-4.88-r1

I think best idea is delete -version of every line. Is there a way to can handle it on linux? The file has more entry all together was 1500 lines only in 32 txt file.

Thanks for help & Nice Weekend Silvio

Silvio
  • 123
  • 1
  • 9
  • Are you sure that the program which generated this list, can not generate it in a different format? For example, where the version number is separated by a space from the package name? Your task would be a lot easier. – Rany Albeg Wein Jan 30 '16 at 02:48

2 Answers2

1

you need to define what difference you want. Set difference is not commutative.

For example

$ comm -23 <(sort file1) <(sort file2)

will give the set difference File1 \ File2 (unique entries in File1), whereas

$ comm -13 <(sort file1) <(sort file2)

will be set difference File2 \ File2

On a real example:

$ comm -23 <(echo -e 'a\nb\nc') <(echo -e 'c\nd\ne')
a
b

$ comm -13 <(echo -e 'a\nb\nc') <(echo -e 'c\nd\ne')
d
e

If you want to do the comparison without the version numbers, first you need to trim them. Based on the sample above it looks like it's -[0-9] is the pattern to look.

$ f() { sed 's/-[0-9].*//' $1 | sort; }; comm <(f file1) <(f file2)

which will give you three columns, unique in file1, unique in file2, common in file1 and file2. Or, using the options mentioned above you can get diffs only.

karakfa
  • 66,216
  • 7
  • 41
  • 56
  • Hello, thank you for answer. I want that at end two files there which has only sys-libs/libseccomp sys-libs/libunwind then i can better saw what is installed and what not on the amd64 tree. Gentoo amd64 and x86 has often same software installed only in other version. When version away i can better see what need to install and what not. – Silvio Jan 30 '16 at 10:34
0
diff -u <(sed 's/-[0-9].*$//' packages32.txt | sort) <(sed 's/-[0-9].*$//' packages64.txt | sort)

sed will remove the -version part of each file before pipe the result to sort. Both results goes to diff. The diff will show lines only in the first file (packages32.txt) starting with - and show lines only in the second file (packages64.txt) starting with +.

Joao Morais
  • 1,885
  • 13
  • 20