0

I'm trying to use the comm command to compare two logs to see which apps have been installed but not removed. I don't want to use awk for this, if possible. Here's and example of the files:

Installed:

2009-03-21 11:43:21 install flex-old:amd54 <none> 3.7.4a-10ubuntu1
2009-03-22 22:55:08 install libubsan0:amd54 <none> 6.3.0-1ubuntu1~14.04

Removed:

2009-03-24 19:53:49 remove libubsan0:amd54 <none> 6.3.0-1ubuntu1~14.04

So the one that would need to be found as different is the "flex-old" line. Here is what I have tried, with some other variations:

comm -23 <(sort install.txt) <(sort removed.txt) > difference.txt

This outputs all of the installed list, not just the ones that aren't in common with the remove list. I've also tried:

comm -3 <(cut -d " " -4f sort install.txt | uniq) <(sort removed.txt | uniq) > what.txt

But, this outputs all the apps from both, but with the removed directly under the install.

  • It strikes me that your package manager should be able to tell you what packages are currently installed on the system. – Kusalananda Feb 18 '18 at 9:14
1

Looks like you were pretty close to me. Based on your samples, the following 1 liner:

comm -23 <(sort install.txt | cut -d" " -f4) <(sort removed.txt | cut -d" " -f4)

Produced this for output for me:

flex-old:amd54

NOTE: You may want to tweak the comm -23. For example, comm -3 may be all you need here.

What I did to test. First, I broke down your commands to test them. I started with:

cut -d " " -4f sort install.txt

Which was clearly broken, so I fixed that to:

sort install.txt | cut -d" " -f4

After that (based on my experience), I was able to re-write your one liner without further testing. If that failed, I would have performed a basic test with comm to see what was wrong, but there was no need this time :]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.