<分区>
我是 linux 初学者。虽然我已经了解了 sed 命令的不同语法,但仍然无法理解这种形式:
sed "s|key: ||"
请有人帮助我理解这种形式的 sed,这里的键可以是任何单词。
我很困惑,它是如何将这里的 key
替换为某些东西的?
<分区>
我是 linux 初学者。虽然我已经了解了 sed 命令的不同语法,但仍然无法理解这种形式:
sed "s|key: ||"
请有人帮助我理解这种形式的 sed,这里的键可以是任何单词。
我很困惑,它是如何将这里的 key
替换为某些东西的?
最佳答案
这是 info sed
:
The 's' command (as in substitute) is probably the most important in 'sed' and has a lot of different options. The syntax of the 's' command is 's/REGEXP/REPLACEMENT/FLAGS'.
The '/' characters may be uniformly replaced by any other single character within any given 's' command. The '/' character (or whatever other character is used in its stead) can appear in the REGEXP or REPLACEMENT only if it is preceded by a '\' character.
这意味着您可以使用 s/foo/bar/g
, s|foo|bar|g
, s#foo#bar#g
, skfookbarkg
或任何其他字符,它们都表示同一件事。 /
仅仅是常规的。
(有趣的事实:这意味着一些英语单词,如 streetlight
、 serenade
和 synonymously
是有效的 sed s
命令。)
关于linux - 使用 sed "s| ACT: ||",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52374114/