I can do
diff filea fileb to see the difference between files. I can also do
head -1 filea to see the first line of filea or fileb. How can I combine these commands to show the difference between the first line of filea and the first line of fileb?
If your shell supports process substitution, try:
diff <(head -n 1 filea) <(head -n 1 fileb)
If you are only comparing the first line of each file, maybe you care about word-level changes within the line, using
dwdiff <(head -n 1 filea) <(head -n 1 fileb)
dwdiff has some nice options, like
-c to colorize the changed words.
sed instead of head:
dwdiff <(sed 1q filea) <(sed 1q fileb)
which the manual for head suggests is more portable than head, as the syntax for head has changed over time
head -1 vs
head -n 1
Also, you could just eyeball the changes, with a bit less typing:
head -n1 -q filea fileb
which displays the two lines, one below the other, for easy visual comparison.