Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare two files in Linux: ignoring first and last lines

I´d like to compare two files, but I don´t want to take into account the first 10 lines, and the last 3 lines of both files. I tried to do it with diff and tail commands, like in here, but without success. how can I do it?

like image 394
Luis Andrés García Avatar asked Jan 28 '13 08:01

Luis Andrés García


1 Answers

Use GNU tail and head:

To ignore the first 10 lines of a file, use tail like this:

tail -n +11 file

To ignore the last 3 lines of a file, use head like this:

head -n -4 file

You can then construct your diff command using process substitution as follows:

diff <(tail -n +11 file | head -n -4) <(tail -n +11 file2 | head -n -4)
like image 172
dogbane Avatar answered Oct 05 '22 05:10

dogbane