I want to diff only the first line of two files, as opposed to the entire file. How would I do that? I only need a solution for the the first line, but if you could specify the number of lines that would be a much better answer.
So diff would return no differences between the following two files:
a
1
2
and:
a
3
4
Best Answer
Here you go:
(this would return nothing what-so-ever).
You could incorporate that into a script to do the things you mention.
To use that, just make the script executable with
chmod +x nameofscript.sh
and then to execute,./nameofscript.sh ~/file1 ~/Docs/file2
That leaves the default # of lines at 1, if you want more append a number to the end of that command.(Or you could do switches in your script with -f1 file1 -f2 file2 -n 1, but I don't recall of the top of my head the case statement for that).
head
returns from the beginning the # of lines as suggested by-n
. If you were to want to do reverse, it would betail -n ${numLines}
(tail does from the end back the number of lines).Edit 5/10/16:
This is specific to Bash (and compatible shells). If you need to use this from something else: