reverse grep to discover values from one list that are not in another list
Sample Input Lists
[user@server]# cat list-full [user@server]# cat list-partial
1 1
2
3 3
4
5 5
6
7 7
8
9 9
10
Sample output
[user@server]# ./list-diff.sh
2
4
6
8
10
[user@server]# ./list-match.sh
1
3
5
7
9
list-match.sh
#!/bin/bash
# this will compare two lists and output the lines that appear in both
for i in `cat list-partial`
do if grep -q -v $i list-full
then echo $i
else
true
fi
done
list-diff.sh
#!/bin/bash
#this will compare two lists and output the lines that appear in the list-full only
for i in `cat list-full`
do if grep -q $i list-partial
then true
else echo $i
fi
done
Example application
You have 2 list a list containing all your servers and another list of the servers with a software package installed.
for i in `cat systems_list_2014-02-20-sorted`
do
if grep -q $i package_listinstalledsystems_example-1.2.3-4.x86_6-sorted
then true
else echo $i
fi
done > systems_without__example-1.2.3-4.x86_6