bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] How not to escape sequence in awk? Or how to unescape seq


From: Aharon Robbins
Subject: Re: [bug-gawk] How not to escape sequence in awk? Or how to unescape sequence for awk?
Date: Sun, 28 Apr 2013 10:56:58 +0300
User-agent: Heirloom mailx 12.5 6/20/10

Hello. Re this:

> Date: Thu, 25 Apr 2013 11:01:41 -0500
> From: Peng Yu <address@hidden>
> To: address@hidden
>
> Hi,
>
> I want awk to print '\<xyz\>'.
>
> ~$ awk -v "x='\<xyz\>'" 'BEGIN{print x}'
> awk: warning: escape sequence `\<' treated as plain `<'
> awk: warning: escape sequence `\>' treated as plain `>'
> '<xyz>'
>
> I could manually do the following, but when the string '\<xyz>\' is
> generated from from another program. I'll have to either have a 3rd
> program to unescape the sequence or have awk stop escaping. Does any
> of the two exist?
>
> ~$ awk -v "x='\\\<xyz\\\>'" 'BEGIN{print x}'
> '\<xyz\>'
> -- 
> Regards,
> Peng

You have to deal with shell quoting issues. In particular, the "..." require
extra escaping of backslashes, over and above what gawk requires. You
can simplify the above to:

        $ gawk -v 'x=\\<xyz\\>' 'BEGIN { print x }'
        \<xyz\>

Gawk always processes values assigned on the command line for escape
sequences, and that cannot be disabled. It looks like for what you are
doing you will need an extra program to process the output of the 3rd
program that you mention above.

Arnold



reply via email to

[Prev in Thread] Current Thread [Next in Thread]