Re: extracting with sed

From: Tom Lanyon <tom_at_netspot.com.au>
Date: Sat, 6 Feb 2010 22:03:23 +1030
Message-Id: <4D42E3D0-222F-4870-BB14-A80EB0D3FC08_at_netspot.com.au>



On 06/02/2010, at 3:30 AM, Bobak, Mark wrote:

> Well, since no one else has answered yet, I’ll show you my (really ugly) solution:
> [oracle_at_msrac201 ~]$ cat log.txt
> SQL> _at_.[%OSAUTH_PREFIX_DOMAIN%]
> SP2-0310: unable to open file ".[FALSE]"
> SQL> spool off
> [oracle_at_msrac201 ~]$ cat log.txt|tail -2|head -1|awk -F[ '{ print$2 }'|awk -F] '{ print $1}'
> FALSE
>
> Yeah, I’m no awk or sed genius. I use tail and head to get only the second line, then I need to use awk twice to parse out around each of the ‘[‘ and ‘]’. Yes, I’m sure there’s a better and cleaner way.

How about just awk?

        awk -F '[\\[\\]]' '/^SP2-/ {print $2}' log.txt

Look for any lines starting with SP2-, split based on '[' or ']' as a field delimiter and print the second field.

Tom--
http://www.freelists.org/webpage/oracle-l Received on Sat Feb 06 2010 - 05:33:23 CST

Original text of this message