10

I am polling a csv file and want to capture the the last 5 lines of the file periodically. Is there a way to do that while skipping the last line. For example

File I'm Polling:

Fooo1,bar1,bar1
Fooo2,bar2,bar2
Fooo3,bar3,bar3
Fooo4,bar4,bar4
Fooo5,bar5,bar5
Fooo6,bar6,bar6
Fooo7,bar7,bar7

Tail command would capture lines 2-6 only.

The problem is that the file keeps growing.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
Sascha
  • 398
  • 6
  • 14

3 Answers3

8

I would suggest you use this:

tail -5 file.csv | head -4
Benoit Lacherez
  • 506
  • 2
  • 8
7

Use this instead:

head -n -1 file.csv

It skips last line Explained here.

Vijay
  • 89
  • 1
  • 4
2

I use sed to delete lines from command output that I know is going to have some amount of header & trailer lines. For instance, to delete the first 3 lines and delete the last line of output:

system "WRKSBS" | sed -e '1,3d;$d'
Kelly Beard
  • 684
  • 1
  • 8
  • 20