What does this mean in a shell script?
| sed 's/ /':'/' | sed 's/ /-/' > file.list
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityAssuming the context is
some-command | sed 's/ /':'/' | sed 's/ /-/' > file.list
Let's break it apart piece by piece. Suppose for example that some-command
is echo 'test of the command'
.
Then sed 's/ /':'/'
replaces the first space by :
.
test of the command
→ test:of the command
After that, sed 's/ /-/'
replaces the new first space by -
test:of the command
→ test:of-the command
This transformation is applied on each line of the output of some-command
.
As mentioned by @Philippos in the comments, it is unclear why :
is unquoted here. It would be better as
some-command | sed 's/ /:/' | sed 's/ /-/' > file.list
But sed
is not restricted to a single replacement per instance. So even better is
some-command | sed 's/ /:/; s/ /-/' > file.list
:
is outside the quoting or why this is double-piped instead of sed 's/ /:/;s/ /-/'
May 2, 2017 at 16:39