我想创建一个需要在多个 HTML 文件中替换的单词列表。我该怎么做?
例如替换:
cat
和dog
parrot
和monkey
fish
和tiger
涵盖选定目录中的所有 HTML 文件。
答案1
您可以将多个sed
表达式放入一个文件中,然后使用以下-f
选项应用它们:
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
例如给定
$ cat > file
The cat sat on the mat.
The parrot chewed on a carrot.
The fish was just a fish.
然后
$ cat > sedfile
s/cat/dog/g
s/parrot/monkey/g
s/fish/tiger/g
$ sed -f sedfile file
The dog sat on the mat.
The monkey chewed on a carrot.
The tiger was just a tiger.