For Programmers: Free Programming Magazines  


Home > Archive > AWK > January 2008 > Re: awk & shell variables containing blanks









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 Re: awk & shell variables containing blanks
Janis Papanagnou

2008-01-17, 6:59 pm

Mark wrote:
> Hi,
>
> Currently I am experiencing a small issue with awk search patterns &
> korn shell variables.
> I simplified my problem to the following example (which will explain
> itself I suppose) :
>
> $ x="a b"
> $ awk '/'$x'/' <file>
> awk: line 1: runaway regular expression /a ...
>
> Can anyone tell me how to get around it? Probably a small thing, but I
> can't seem to find the answer ...


As long as there are no regexp meta-characters in the search string
pass them as awk variables...

awk -v pattern="$x" '$0~pattern' file


Janis

>
>
> Thanks!
>
> Mark

Sponsored Links







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

Copyright 2008 codecomments.com