0

What does this mean in a shell script?

| sed 's/ /':'/' | sed 's/ /-/' > file.list
5

Assuming 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 commandtest:of the command

After that, sed 's/ /-/' replaces the new first space by -

test:of the commandtest: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
  • You could add that there is no obvious reason why the : is outside the quoting or why this is double-piped instead of sed 's/ /:/;s/ /-/' – Philippos May 2 '17 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.