LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   strip last lines off pipe (https://www.linuxquestions.org/questions/linux-newbie-8/strip-last-lines-off-pipe-4175540022/)

usao 04-17-2015 04:20 PM

strip last lines off pipe
 
I have a datastream going through a pipe,and I need to strip-out (remove) the last 3 lines (trailer) from that stream so that it doesn't go down to the next command in the stream.
ive tried combinations of head/tail, but that all assumes you know ahead of time how many lines are in the stream to begin with...

joe_2000 04-17-2015 06:46 PM

Quote:

Originally Posted by usao (Post 5349098)
but that all assumes you know ahead of time how many lines are in the stream to begin with...

Hmm, no. You could just do

Code:

mycommand | head -n -3
Also see head man page
Code:

      -n, --lines=[-]K
              print the first K lines instead of the first 10; with the leading '-', print all but the last K lines of each file



All times are GMT -5. The time now is 06:14 PM.