如何“搜索和替换”许多文件?


Answers:



1

sed浮现在脑海。例:

sed s/cat/dog/ <input >output

这会在一行中搜索cat,并将dog放在文件输入中的位置,然后写入文件输出。



0

您可以在Ex模式下使用Vim:

for b in *.txt
do
  ex -sc '%s/OLD/NEW/g|x' "$b"
done
  1. % 选择所有行

  2. s 替代

  3. g 替换每一行中的所有实例

  4. x 保存并关闭

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.