davidhood2 davidhood2 - 1 year ago 68
Bash Question

Using grep to compare two lists of Python packages

I want to generate the list of packages install in Python 3, the list of all packages in Python 2.7 and find all entries in the 2.7 list not in the Python 3 list.

Generating the list is easy:

pip freeze
pip3.4 freeze

Searching for a package in the list is equally trivial
pip freeze | grep "wheel"
for example

However, if I want to search for intersections between the list, or in this instance non-intersections I would expect to use something like this
pip freeze | grep -n pip3.4 freeze

However it tells me that, obviously the parameter for grep
...is not a file or directory
. My shell scripting is rusty and I vaguely remember there should be a simple way of doing this other than piping both lists to files?

Answer Source

you can use also comm command as below

comm -12 <(pip freeze) <(pip3.4 freeze)

to search for intersections;

grep -f <(pip freeze) <(pip3.4 freeze)