Take the 2-minute tour ×  Is it possible to check if first line
of two files is equal using diff(or another easy bash command)?
[Generally checking equality of first/last k lines, or even
lines i to j]  share|improve this question add comment  4
Answers  up vote 7 down vote accepted  To diff the first k lines
of two files:  $ diff <(head -k file1) <(head -k file2)
Similary, to diff the last k lines:  $ diff <(tail -k file1)
<(tail -k file2)  To diff lines i to j:  diff <(sed -n 'i,jp'
file1) <(sed -n 'i,jp' file2) share|improve this answer What
does p mean in 'i,jp'? –  a-z May 3 '12 at 8:59 p means print.
–  dogbane May 3 '12 at 9:13 and to check equality: if diff ...;
then echo "equal"; else echo "not equal"; fi –  glenn jackman
May 3 '12 at 10:12 add comment  My solution seems rather basic
and beginner when compared to dogbane's above, but here it is
all the same!  echo "Comparing the first line from file $1 and
$2 to see if they are the same."  FILE1=`head -n 1 $1`
FILE2=`head -n 1 $2`  echo $FILE1 > te