bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] How to unescape a string?


From: david kerns
Subject: Re: [bug-gawk] How to unescape a string?
Date: Tue, 23 Oct 2018 19:01:20 -0700

got it!
$  awk 'BEGIN { a = "a\\\\b\\\""; q = sprintf("%c",39);print a; c = "sed -e
" q "s/\\\\\\(.\\)/\\1/g" q ; print a |& c; close(c,"to"); c |& getline
b;close(c); print b}'
a\\b\"
a\b"


On Tue, Oct 23, 2018 at 6:52 PM david kerns <address@hidden> wrote:

> here's sed:
> $ echo "a\\\\b\\\"" ; echo "a\\\\b\\\"" | sed -e 's/\\\(.\)/\1/g'
> a\\b\"
> a\b"
>
> ...trying to use sed from awk ... I'm still missing something
>
> $ awk 'BEGIN{a="a\\\\b\\\"";q=sprintf("%c",39);print a;c="sed -e
> "q"s/\\\\\\(.\\)/\\1/g"q;print c;print a |& c;c |& getline b;close(c);print
> b}'
> a\\b\"
> sed -e 's/\\\(.\)/\1/g'
> (hangs)
>
>
> On Tue, Oct 23, 2018 at 4:36 PM david kerns <address@hidden>
> wrote:
>
>>
>> I was hoping this would, but it doesn't .. perhaps it will spur someone
>> else :/
>>
>> awk 'BEGIN { a ="a\\\\b\\\""; print a; gensub(/\\(.)/, "\1", "g", a);
>> print a }'
>> a\\b\"
>> a\\b\"
>>
>>
>> On Tue, Oct 23, 2018 at 2:35 PM Peng Yu <address@hidden> wrote:
>>
>>> Hi,
>>>
>>> I have a string in which the double quote character is escaped as \"
>>> (baskslash character and double quote character) and the backslash
>>> character is escaped as \\ (double backslash). Does anybody know a
>>> simple way to unescape such a string in awk? (The following is a
>>> simple example of the input and the output.) Thanks.
>>>
>>> a\\b\" -> a\b"
>>>
>>> --
>>> Regards,
>>> Peng
>>>
>>>


reply via email to

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