title: comparing two files with grep bash with while loop
body: <p>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...</p>
  
  <p>Input (part of dpkg.log file):</p>
  
  <pre><code>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 &gt; log1.txt
  sed -nf p2bRemoved.sed dpkg.log|sort|uniq -c&gt; log2.txt
  #read installed file line by line
  
  while read -r num prog; do
  
  grep "$prog" log2.txt
  echo "$prog"
  
  
  done &lt;log1.txt &gt; p2b.out
  </code></pre>
  
  <p>the output is:</p>
  
  <pre><code>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
  </code></pre>