I have a couple of packages lists, with hundreds of entries, and I would like to find the differences of them.
The contents of the files look like
File 1:
somepackage1 0.1
somepackage2 5.6
somepackage3 1.3-1
etc...
File 2:
somepackage1 0.1
somepackage2 5.7
somepackage3 1.3-1
somepackage4 0.1
etc...
I'm looking for a couple of commands or a script that can produce all the new packages that were added. Not just the version numbers, but if a new package was added.
So, for example the command or script would output somepackage4
given the above two files.
I've been playing with some commands, but can't get any of them work properly. Does anyone have a good way of doing this?
You seem to want to compare the first column in the files and print the lines that are unique in the second one. Use comm
:
comm -13 <(awk '{print $1}' file1 | sort) <(awk '{print $1}' file2 | sort)
For your input, it'd produce:
somepackage4
you can use grep
to find packages in listed in file2 but not in file1
grep -vf <(cut -d' ' -f1 file1) <(cut -d' ' -f1 file2)
使用awk
awk 'NR==FNR{a[$1];next}!($1 in a){print $1}' file1 file2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.