I need to loop through a file while comparing it to another file to get what is the same. Right now it is a while loop with grep since that was what was suggested. Currently it is returning the entire log1 file with the number removed. The sed Files separate the files that are installed and removed and remove the time and date and the word install or remove. So $prog is working it's just not matching to anything in log2. Not allowed to use awk, or I would have been done already...
Input (part of dpkg.log file):
2018‐01‐19 21:33:09 status half‐configured man‐db:amd64 2.6.7.1‐1ubuntu1
2018‐01‐19 21:33:09 status half‐installed flex:amd64 2.5.35‐10.1ubuntu2
2018‐01‐19 21:33:09 status triggers‐pending install‐info:amd64 5.2.0.dfsg.1‐2
2018‐01‐19 21:33:09 status triggers‐pending man‐db:amd64 2.6.7.1‐1ubuntu1
2018‐01‐19 21:33:14 status installed libfl‐dev:amd64 2.5.35‐10.1ubuntu2
2018‐01‐19 21:33:14 status unpacked flex:amd64 2.5.35‐10.1ubuntu2
2018‐01‐19 21:33:14 status unpacked libfl‐dev:amd64 2.5.35‐10.1ubuntu2
#!/bin/bash
sed -nf p2aInstalled.sed dpkg.log|sort|uniq -c > log1.txt
sed -nf p2bRemoved.sed dpkg.log|sort|uniq -c> log2.txt
#read installed file line by line
while read -r num prog; do
grep "$prog" log2.txt
echo "$prog"
done <log1.txt > p2b.out
the output is:
half‐configured man‐db:amd64 2.6.7.1‐1ubuntu1
half‐installed flex:amd64 2.5.35‐10.1ubuntu2
triggers‐pending install‐info:amd64 5.2.0.dfsg.1‐2
triggers‐pending man‐db:amd64 2.6.7.1‐1ubuntu1
libfl‐dev:amd64 2.5.35‐10.1ubuntu2
unpacked flex:amd64 2.5.35‐10.1ubuntu2
unpacked libfl‐dev:amd64 2.5.35‐10.1ubuntu2