我正在尝试在awk中编写一个脚本(除其他外)用两个连续的双引号替换双引号的所有实例。但出于某种原因,我似乎无法正确地逃避我的双引号。
例如:
Mary had a "little" lamb
会变成
Mary had a ""little"" lamb
非常感谢!
答案 0 :(得分:3)
你可以这样做:
echo 'Mary had a "little" lamb' | awk '{ gsub(/"/, "&&") } 1'
输出:
Mary had a ""little"" lamb
最后1
调用awk的默认块{ print $0 }
。
sed更短:
echo 'Mary had a "little" lamb' | sed 's/"/&&/g'