diff, compare only first lines?

Is there anyway to get diff to compare two directories, but only consider files "different" if their first line is different? For example, the files

Code:
{ * ver 1.234 * }
content A
content B
and
Code:
{ * ver 1.234 * }
content C
content D
are the "same". I just need a list of all the files that are different in this way. I checked the man page, but I didn't see anything that would give me this kind of control. Any ideas? Thanks!
 
AFAIK there is no option to do this built in diff, but this can be done with a not to complicated shell script.

There's also mergemaster(8) which more or less does what you want, maybe you can (re)use (parts of) it.
 
Perhaps you can use cmp for that?

Given two files foo and bar.
foo:
foo
bar

bar:
foo
baz

# cmp foo bar gives:
Code:
foo bar differ: char 7, line 2
So:
# cmp foo bar | grep "line 1" || echo "Different"
is what you want?
 
So instead of diff'ing the entire files, you just want to diff the first line of each file, i.e., the "head -n 1" of each file?

Brett
 
Code:
find dir1 -type f | while read i; do
   ( [ `head -n1 "$i"` = `head -n1 "dir2/$i"` ] && echo "$i same" ) \
      || echo "$i different"
done
 
Back
Top