Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you skip the last line w/ awk?

Tags:

unix

awk

I am processing a file with awk and need to skip some lines. The internet dosen't have a good answer.

So far the only info I have is that you can skip a range by doing:

awk 'NR==6,NR==13 {print}' input.file

OR

awk 'NR <= 5 { next } NR > 13 {exit} { print}' input.file

You can skip the first line by inputting:

awk 'NR < 1 { exit } { print}' db_berths.txt

How do you skip the last line?

like image 392
ovatsug25 Avatar asked Aug 08 '12 14:08

ovatsug25


1 Answers

One way using awk:

awk 'NR > 1 { print prev } { prev = $0 }' file.txt

Or better with sed:

sed '$d' file.txt
like image 111
Steve Avatar answered Sep 29 '22 16:09

Steve