Linux bash 中的“sed”命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3984824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"sed" command in bash
提问by ajsie
Could someone explain this command for me:
有人可以为我解释这个命令:
cat | sed -e 's,%,$,g' | sudo tee /etc/init.d/dropbox << EOF
echo "Hello World"
EOF
What does the "sed" command do?
“sed”命令有什么作用?
采纳答案by Hyman Kelly
sed
is the Stream EDitor. It can do a whole pile of really cool things, but the most common is text replacement.
sed
是流编辑器。它可以做一大堆非常酷的事情,但最常见的是文本替换。
The s,%,$,g
part of the command line is the sed
command to execute. The s
stands for substitute, the ,
characters are delimiters (other characters can be used; /
, :
and @
are popular). The %
is the pattern to match (here a literal percent sign) and the $
is the second pattern to match (here a literal dollar sign). The g
at the end means to g
lobally replace on each line (otherwise it would only update the first match).
s,%,$,g
命令行的部分是sed
要执行的命令。的s
代表的替代品,所述,
字符是定界符(其他字符均可使用; /
,:
和@
是流行)。该%
是要匹配的模式(这里是文字百分号),并且$
是第二个模式匹配(此处文字美元符号)。所述g
在末端手段g
lobally取代在每行上(否则将只更新第一匹配)。
回答by Lekensteyn
It reads Hello World
(cat
), replaces all (g
) occurrences of %
by $
and (over)writes it to /etc/init.d/dropbox
as root.
它读取Hello World
( cat
),替换所有 ( g
) 出现的%
by$
并(覆盖)以/etc/init.d/dropbox
root 身份将其写入。
回答by codaddict
Here sed
is replacing all occurrences of %
with $
in its standard input.
这sed
是在其标准输入中替换所有出现的%
with $
。
As an example
举个例子
$ echo 'foo%bar%' | sed -e 's,%,$,g'
will produce "foo$bar$".
将产生“foo$bar$”。
回答by Anil Vishnoi
sed is a stream editor. I would say try man sed.If you didn't find this man page in your system refer this URL:
sed 是一个流编辑器。我想说试试 man sed。如果你在你的系统中没有找到这个手册页,请参考这个 URL: