For Programmers: Free Programming Magazines  


Home > Archive > AWK > September 2004 > regexpr









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author regexpr
Laurent Deniau

2004-09-09, 3:56 pm

I would like to catch all the lines which end by (GCC warning which
cannot be disabled)

warning: (near initialization for `ooc_cls#####_.alloc')

where ##### is [A-Za-z0-9_]+ and means (roughly) a valid token.

I tried

/"warning: (near initialization for `ooc_cls"[A-Za-z0-9_]+"_.alloc')"$/

but I get an error at the ')'

line 4: syntax error near unexpected token `)'
line 4: `/"warning: (near initialization for
`ooc_cls"[A-Za-z0-9_]+"_.alloc')"/ '

the awk script is in a shell script so I should put a ' instead of ':

#!/bin/sh
make 2>&1 | awk '\
/"warning: (near initialization for `ooc_cls"[A-Za-z0-9_]+"_.alloc')"/ \
{ print $0; }
#EOF

But still does not work...

Any idea where I missed a '' ?

ld.
Stepan Kasal

2004-09-09, 3:56 pm

Hi,

In article <chn3q6$5v7$1@sunnews.cern.ch>, Laurent Deniau wrote:
> warning: (near initialization for `ooc_cls#####_.alloc')

....
> I tried
> /"warning: (near initialization for `ooc_cls"[A-Za-z0-9_]+"_.alloc')"$/
> but I get an error at the ')'


The regex to match the above line could be
/warning: \(near initialization for `ooc_cls[A-Za-z0-9_]+_\.alloc'\)$/

The parens and the dot are meta-chars and you have to escape them.

When you put this into shell script between single quotes, you have to
know that backslash is not special inside them. So you can leqave all
backslashes as they are, but to insert the single quote, you have to use
'''
or
'"'"'
Basically, you have to get out of single quotes and then specify the single
quote using a backslash or double quotes.

So:

#!/bin/sh
make 2>&1 | awk '\
/warning: \(near initialization for `ooc_cls[A-Za-z0-9_]+_\.alloc'''\)$/
{ print $0; }'
>


should work.

HTH,
Stepan
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com