Search code examples
bashshellheadbsd

bash shell display first part of file using BSD head


Here's the file:

line1
line2
⋮
line10
Total
Update time

I want to have the first part of file except for the last 2 lines.

The output should look like this:

line1
line2
⋮
line10

How can i achieve this using BSD head? or other oneliner?

Thanks!


Solution

  • using awk, this will print all the lines except last two lines.

      awk '{a[j++]=$0}END{for(i=0;i<j-2;i++){print a[i]}}' filename