我想使用 shell 脚本在文件 sat '1.txt' 中找到一个字符串 say 'foo' 并将 'foo' 替换为 'bar' 并将输出存储到另一个文件 say '2.txt' 而不做任何修改在 1.txt 中。
所以 '1.txt' 将包含 'foo' 本身,但 '2.txt' 现在将包含 '1.txt' 的所有内容,'foo' 替换为 'bar'
我在 bash 中使用这个命令
sed -i "s/foo/bar/g" "1.txt" > 2.txt
但它不起作用。
最佳答案
删除 -i
选项,因为它代表就地操作。
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied)
(sed(1) 手册页)
关于linux - 查找字符串并将替换的字符串存储在其他文件 shell 脚本中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37176261/