2

Here's my case- I have a package named say foo-1.2.3. I want to know which package it installs. So, I install it in a fakeroot approach and make a list of all files it install in a file called FILES

Suppose I want to upgrade it to foo-1.2.4. In the same way, I created the FILES file for it. I know that if the name of the shared library changes, all the packages dynamically linked to it needs to be re-compiled. So I want to write a bash script which will notify me.

For example, say the old FILES contains-

/usr/lib/libfoo.so.1
/usr/lib/libfooabc.so.1
/usr/lib/something.so.1
/usr/share/doc/foo-1.2.3/whatever

And let's say the new FILES contains-

/usr/lib/libfoo.so.2
/usr/lib/libfooabc.so.2
/usr/lib/something.so.1
/usr/share/doc/foo-1.2.4/whatever

I want the script to notify me that, /usr/lib/libfoo.so.1 and /usr/lib/libfooabc.so.1 have changed.

I tried this

grep -F -x -f old new|grep -E *\.so\.*

But it doesn't work as expected when the file old is-

/usr/lib/libfooabc.so.1
/usr/lib/libfoo.so.1
/usr/lib/libfoo.so.2
/usr/lib/something.so.1
/usr/share/doc/foo-1.2.3/whatever

And new is-

/usr/lib/libfoo.so.2
/usr/lib/libfoo.so.3
/usr/lib/libfooabc.so.2
/usr/lib/something.so.1
/usr/share/doc/foo-1.2.4/whatever

The output is-

/usr/lib/libfoo.so.2
/usr/lib/something.so.1

The desired output is-

/usr/lib/libfooabc.so.1
/usr/lib/libfoo.so.1
1

1 Answer 1

2

I came up with two options using diff that should work for you.

Using diff -u and sed:

diff -u old new | sed  -n 's/^-\(.*\.so\..*\)/\1/p'
/usr/lib/libfoo.so.1
/usr/lib/libfooabc.so.1
  • That command outputs the full diff between the two files, and we use sed to filter out only the changes from the 'old' file (indicated by a leading -), and further filter on the diff containing .so.. To strip out the - from the diff output we use a backreference to print everything but that.

Using diff output formatting and grep

Two variants on the same thing; the second one is shorter, they both behave identically to each other and the previous example.

diff --old-line-format='%L' --unchanged-line-format= --new-line-format= old new | grep '\.so\.'

or slightly better:

diff --changed-group-format='%<' --unchanged-line-format=  old new | grep '\.so\.'

You may be able to get diff to do the job entirely by itself - it does have regex filtering (-I ignore flag), but it behaves oddly when you need to invert the regex. I've never had much luck with it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .