这个 sed 命令是什么意思?

Mat*_*ias 0 sed shell-script

这在 shell 脚本中是什么意思?

| sed 's/ /':'/' | sed 's/ /-/' > file.list
Run Code Online (Sandbox Code Playgroud)

Fox*_*Fox 5

假设上下文是

some-command | sed 's/ /':'/' | sed 's/ /-/' > file.list
Run Code Online (Sandbox Code Playgroud)

让我们一块一块地拆开它。例如,假设some-commandecho 'test of the command'

然后sed 's/ /':'/'用 替换第一个空格:

test of the command ? test:of the command

之后,sed 's/ /-/'将新的第一个空格替换为-

test:of the command ? test:of-the command

此转换应用于 的输出的每一行some-command


正如@Philippos 在评论中提到的,目前还不清楚为什么:这里没有引用。这会更好

some-command | sed 's/ /:/' | sed 's/ /-/' > file.list
Run Code Online (Sandbox Code Playgroud)

sed不限于每个实例一次替换。所以更好的是

some-command | sed 's/ /:/; s/ /-/' > file.list
Run Code Online (Sandbox Code Playgroud)