我处于一种情况,在找到匹配项后,我需要替换一些特定的单词。 条件是标记应以“ detailSelection”开头,此后无论哪里有WORD1,我都需要将其替换为WORD2。
这是一个大文件的一小段,我必须成百上千个文件来做。
"detailSelection": {
"name": "Alarm Detail",
"type": "form-operation",
"requireSelection": true,
"dataSelection": {
"typeSelection": {
"domain": "ossm",
"package": "WORD1",
"type": "WORD1"
},
输出应类似于:
"detailSelection": {
"name": "Alarm Detail",
"type": "form-operation",
"requireSelection": true,
"dataSelection": {
"typeSelection": {
"domain": "ossm",
"package": "WORD2",
"type": "WORD2"
},
答案 0 :(得分:0)
非常简单,您需要使用sed命令
sed -i 's/WORD1/WORD2/g' filename.txt
-i将在文件内部执行此替换。换句话说,它将更改文件。如果您要创建一个新文件,那么
sed 's/WORD1/WORD2/g' filename.txt > newfile.txt