Re: extracting with sed

  • From: Tom Lanyon <tom@xxxxxxxxxxxxxx>
  • To: Mark.Bobak@xxxxxxxxxxxx, mhdmehraj@xxxxxxxxx
  • Date: Sat, 6 Feb 2010 22:03:23 +1030

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@msrac201 ~]$ cat log.txt
> SQL> @.[%OSAUTH_PREFIX_DOMAIN%]
> SP2-0310: unable to open file ".[FALSE]"
> SQL> spool off
> [oracle@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--
//www.freelists.org/webpage/oracle-l


Other related posts: