Register
It is currently Thu Apr 24, 2014 7:30 pm

capturing every 5th line of output of a command


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue Nov 23, 2010 11:00 am   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
Hi everyone,

I was wondering is there a one liner to print every 5th line of the standard
output of a command into a file?

I run a command ./coreInfo filename and I get

garbage
garbage
garbage
garbage
Info I care about
garbage
garbage
garbage
garbage
Info I care about
garbage
garbage
garbage
garbage
Info I care about

I know I could process it after being written to a file, but I was wondering if there is a way to directly do it as the command runs.

Ted


Top
 Profile  
 PostPosted: Tue Nov 23, 2010 3:14 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 657
Location: Des Moines, Iowa
Try this

./coreInfo filename | sed -n '0~5p' > newfile

NOTE: this must be the GNU version of SED or it won't work ;)
IE: Fails on solaris, works on Linux ;)


My TEST:
[crouse@archie ~]$ cat TEMP | sed -n '0~5p'
Info I care about
Info I care about
Info I care about
[crouse@archie ~]$

Quote:
[crouse@archie ~]$ cat TEMP
garbage
garbage
garbage
garbage
Info I care about
garbage
garbage
garbage
garbage
Info I care about
garbage
garbage
garbage
garbage
Info I care about


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP