【发布时间】:2021-03-10 11:21:20
【问题描述】:
我需要使用替换文件来检查单词 he 或“he”的完全匹配,但不替换天气中的“he”,所以我决定在 macOS 上使用 sed 命令。我尝试同时使用双引号和单引号,但它不会改变任何东西
sed 's/\<he\>/it/g' file-he.yaml > file-it.yaml
这是输入文件file-he.yaml。
name: "QBERT Utterance Understanding Search Plus Siri he"
topics:
- weatherEvent
- he
environment_variables:
LANG: "he"
预期的输出是
name: "QBERT Utterance Understanding Search Plus Siri it"
topics:
- weatherEvent
- it
environment_variables:
LANG: "it"
我也试过了:
sed 's/"he"/it/g' file-he.yaml > file-it.yaml
它甚至取代了天气中出现的“他”。知道这是为什么吗?
【问题讨论】:
-
请更新问题以在对您的文件运行替换后包含预期的输出 (
file-he.yaml) -
添加了预期的输出@markp-fuso