naumcho
naumcho

Reputation: 19881

Ignoring specific differences in diff

When doing recursive diffs I want to ignore expected differences/translations - is there a way to do that with standard unix tools?

E.g.

file1:
1 ...
2 /path/to/something/ver1/blah/blah
3 /path/to/something/ver1/blah/blah
4 ...

file2:
1 ...
2 /path/to/something/ver2/blah/blah
3 /path/to/something/ver3/blah/blah
4 ...

I want to be able to do something like:

diff file1 file2 --ignore-transltion "ver1>ver2"

This should show only show me that line 3 is different

Does anyone know of a good way to do that? I can easily write a perl script to do it but i will end up re-implementing most of the rest of the functionality of 'diff'.

Update: My goal is to run this on directories with different versions of the same files with "diff -r" so I can spot unexpected differences in versions.

Upvotes: 4

Views: 471

Answers (2)

Max Nanasy
Max Nanasy

Reputation: 6121

The version of diff I have (GNU diffutils 2.8.1) supports diff -I:

-I RE  --ignore-matching-lines=RE
       Ignore changes whose lines all match RE.

It might not be exactly what you want, but in the specific case in your question, diff -I'/path/to/something/ver[12]/blah/blah' seems like it should work, although I'm not sure it actually does work when I test it.

Upvotes: 1

msw
msw

Reputation: 43487

This works:

$ sed  -e 's/who/what/g' -e 's/fido/kitty/g' /etc/services | diff - /etc/services
38c38
< whatis    43/tcp      nicname
---
> whois     43/tcp      nicname
183c183
< what      513/udp     whatd
---
> who       513/udp     whod
568c568
< binkp     24554/tcp   # binkp kittynet protocol
---
> binkp     24554/tcp   # binkp fidonet protocol
...

Where your sed script would be constructed by a program (and have stronger regexps).

Upvotes: 2

Related Questions