LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 808

Rep: Reputation: 216Reputation: 216Reputation: 216
Quote:
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

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
 
1 members found this post helpful.
  


Reply


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


All times are GMT -5. The time now is 08:52 PM.

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