I was testing some and from this string try to remove all "
, but not \"
cat file
The quick brown fox "jumps", over the 'lazy \"dog\"'
result requested: The quick brown fox jumps, over the 'lazy \"dog\"'
I have seen a working solution for sed
, but I like awk
This code seem to work, but for some reason it does remove a blank space after the fox
, why?
awk '{gsub(/[^\\]\"/,x)}1' file
The quick brown foxjump, over the 'lazy \"dog\"'
As far as I understand this means not \ and "
, so why is the space gone?
EDIT:
I found why
not \
can is any characters but not \
, so space is gone and the s
in jumps
Any Idea on how to fix this in awk
?
gensub
should work, but not very portable.
---------- Post updated at 13:26 ---------- Previous update was at 12:57 ----------
I found two working version.
Fist is not perfect, but is portable.
Second is less portable.
awk '{gsub(/\\\"/,"_#_");gsub(/\"/,x);gsub(/_#_/,"\\\"")}1'
awk '{print gensub(/([^\\])\"/, "\\1", "g")}'