ovatsug25
ovatsug25

Reputation: 8606

how do you skip the last line w/ 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?

Upvotes: 18

Views: 18748

Answers (2)

giddi
giddi

Reputation: 103

You can try:

awk 'END{print NR}' file

Upvotes: -4

Steve
Steve

Reputation: 54502

One way using awk:

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

Or better with sed:

sed '$d' file.txt

Upvotes: 20

Related Questions