简体   繁体   English

bash中的“sed”命令

[英]“sed” command in bash

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”命令有什么作用?

sed is the Stream EDitor . sedStream EDitor It can do a whole pile of really cool things , but the most common is text replacement. 它可以做很多很酷的事情 ,但最常见的是文本替换。

The s,%,$,g part of the command line is the sed command to execute. 命令行的s,%,$,g部分是要执行的sed命令。 The s stands for substitute, the , characters are delimiters (other characters can be used; / , : and @ are popular). s代表替代,所述,字符是定界符(其它字符可用于; /:@是流行)。 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). 所述g在结束手段g lobally每行(否则将只更新第一匹配)取代。

Here sed is replacing all occurrences of % with $ in its standard input. 这里sed用标准输入中的$替换所有出现的%

As an example 举个例子

$ echo 'foo%bar%' | sed -e 's,%,$,g'

will produce "foo$bar$". 将产生“foo $ bar $”。

它读取Hello Worldcat ),用$替换所有( g%的出现,并且(over)以root身份将其写入/etc/init.d/dropbox

sed is a stream editor. sed是一个流编辑器。 I would say try man sed.If you didn't find this man page in your system refer this URL: 我会说尝试man sed。如果你没有在你的系统中找到这个手册页,请参考以下URL:

http://unixhelp.ed.ac.uk/CGI/man-cgi?sed http://unixhelp.ed.ac.uk/CGI/man-cgi?sed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM