如何在目录中以递归方式将"XXX" | {"Foo", "Bar"}
替换为"YYY" | {"Foo"}
?
我想使用sed
,但这里的特殊字符很棘手。
答案 0 :(得分:1)
使用find
和xargs
的一种方式:
find . -type f -print0 | xargs -0 sed -i -r 's/"XXX" \| \{"Foo", "Bar"\}/"YYY" \| \{"Foo"\}/g'
答案 1 :(得分:0)
使用perl:
> find . -type f|xargs perl -p -e 's/"XXX" \| {"Foo", "Bar"}/"YYY" \| {"Foo"}/g
答案 2 :(得分:0)
这可能适合你(GNU sed):
find . -type f -print0 |
xargs -0 sed -i '/"XXX"\s*|\s*{\s*\("[^"]*"\)\s*,\s*"[^"]*"\s*}/s//"YYY" | {\1}/g'