Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-17-2015, 05:20 PM   #1
Registered: Dec 2011
Location: Chandler, AZ
Posts: 280

Rep: Reputation: Disabled
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...

Last edited by usao; 04-17-2015 at 05:22 PM.
Old 04-17-2015, 07:46 PM   #2
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Arch, Debian
Posts: 849

Rep: Reputation: 245Reputation: 245Reputation: 245
Originally Posted by usao View Post
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

mycommand | head -n -3
Also see head man page
       -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
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to ignore Pipe in Pipe delimited file? rohit_shinez Programming 29 08-14-2013 12:53 AM
[SOLVED] How to handle a broken pipe exception (SIGPIPE) in FIFO pipe? zyroot998 Programming 5 03-03-2011 09:10 PM > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration