bashsolaris

How can I automatically disregard the last three lines of a file?


I am using the following command:

 head -36 file.txt > file1.txt

where the file is 39 lines , but the thing is i'm checking that the file is 39 lines and so place the number 36 in the comment. So is there a way that the command calculates the number of lines and deduct the last 3 lines ?


Solution

  • And here is awk only solution (no process substitution, piping, etc.)

    awk 'NR==FNR{k++;next}FNR<=k-3' file.txt file.txt
    

    Explanation: