# diff, compare only first lines?



## RazorX (Jun 19, 2009)

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


```
{ * ver 1.234 * }
content A
content B
```
and

```
{ * 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!


----------



## Carpetsmoker (Jun 22, 2009)

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.


----------



## lme@ (Jun 30, 2009)

Perhaps you can use cmp for that?

Given two files foo and bar.
foo:
foo
bar

bar:
foo
baz

`# cmp foo bar` gives:

```
foo bar differ: char 7, line 2
```
So:
`# cmp foo bar | grep "line 1" || echo "Different"`
is what you want?


----------



## estrabd (Jul 1, 2009)

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


----------



## kiyolee (Jul 2, 2009)

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


----------

