BashScripts.org
http://bashscripts.org/forum/

capturing every 5th line of output of a command
http://bashscripts.org/forum/viewtopic.php?f=8&t=1254
Page 1 of 1

Author:  afflictedd2 [ Tue Nov 23, 2010 11:00 am ]
Post subject:  capturing every 5th line of output of a command

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

Author:  crouse [ Tue Nov 23, 2010 3:14 pm ]
Post subject:  Re: capturing every 5th line of output of a command

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:
[[email protected] ~]$ cat TEMP | sed -n '0~5p'
Info I care about
Info I care about
Info I care about
[[email protected] ~]$

Quote:
[[email protected] ~]$ 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

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com