0

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
slyalys
  • 59
  • 6
  • 1
    Please post both Input_file(s) in code tags with expected output in code tags too. – RavinderSingh13 Feb 17 '18 at 09:23
  • Please post both the Input_file(s) in CODE TAGS, I could see only 1 file is posted as of now. – RavinderSingh13 Feb 17 '18 at 09:44
  • Please include example input and expected output. Without that, it's too hard to understand what you're trying to do. – janos Feb 17 '18 at 09:52
  • He didn't really give an expected output, just said find the files they have in common, after doing uniq c its just a number with files, I have to see what files they have in common. Go line by line to see if they match with grep. – slyalys Feb 17 '18 at 10:04
  • does this help? https://stackoverflow.com/questions/373810/unix-command-to-find-lines-common-in-two-files – Sundeep Feb 17 '18 at 10:19
  • comm was the first part, that set up the sed @Sundeep that does help a little. I think this assignment is a little pointless in teaching grep. – slyalys Feb 17 '18 at 10:31
  • I am still not clear with your question.. but if it boils down to finding common lines between two files using grep, then use `grep -Fxf f1 f2` – Sundeep Feb 17 '18 at 10:33

0 Answers0