[Novalug] scripting

Mark Smith mark@winksmith.com
Mon Mar 2 17:35:26 EST 2009


using grep and cut:

	cat com_get* | grep ^Logically | cut -d ' ' -f 5 | sort

sed is a lot of fun too:

	cat com_get* | sed '/^Logically/!d; s/.* \(.*\)/\1/'

i always think of awk as a bigger program (true or not) so i try
to avoid it.  in anycase, perl is almost always a better choice for
anything awk can do (IMO).

if there's only one file name to input avoid running cat (or more):

	< com_get | program

or more traditionally:

	program < com_get

having said that, this is linux, try them all.

On Mon, Mar 02, 2009 at 09:58:32PM +0100, Miguel Gonz?lez Casta?os wrote:
> Hi guys,
> 
>   I am trying to achieve a very simple thing.
> 
>   I am parsing a log file that has a bunch of lines like:
> 
>   Logically move media ID XU0479
>   Logically move media ID XU0480
> 
>   to get the 5th word:
> 
>   more com_get* | grep Logically | awk '{print $5}' | sort > file
> 
>   However, I'd like to have those entries separated with spaces and no 
> each entry in a different line. Any way to do that?

-- 
Mark Smith
mark@winksmith.com
mark@tux.org



More information about the Novalug mailing list