我有一个问题sed
,我可以使用以下简单示例重新创建。
考虑以下输入文件 ( input.txt ):
C:\A\quick\brown\fox\ jumps over the lazy dog
C:\A\quick\brown\fox\ ran with the hounds
Run Code Online (Sandbox Code Playgroud)
我想生成以下输出
C:\Animal\ jumps over the lazy dog
C:\Animal\ ran with the hounds
Run Code Online (Sandbox Code Playgroud)
我尝试使用 sed 创建一个简单的 shell 脚本,但它没有执行所需的替换。这是我的脚本:
FROM_PATTERN="C:\A\quick\brown\fox\"
TO_PATTERN="C:\Animal\"
#FROM_PATTERN="C:\\A\\quick\\brown\\fox\\" # Escaping backslash does not help either
#TO_PATTERN="C:\\Animal\\" # Escaping backslash does not help either
sed 's/$FROM_PATTERN/$TO_PATTERN/g' input.txt
#sed 's/"$FROM_PATTERN"/"$TO_PATTERN"/g' input.txt # Quoting the pattern does not help either
Run Code Online (Sandbox Code Playgroud)
我正在运行bash
版本GNU bash, version 4.4.12(3)-release-(x86_64-unknown-cygwin)