Skip to main content
4 of 5
edited tags
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Can sed process lines that I make in sed?

I want sed to split lines and then process those lines.

E.g. sed 's/,/\n/g' | sed -n '/foo/p'

Can that be done in one sed command in general so that I do not need shell piping?

Example:

echo oof,foo | sed 's/,/\n/g' | sed -n '/foo/p'

Outputs (in Ubuntu):

foo

But if I just

echo oof,foo | sed -n 's/,/\n/g;/foo/p'

it prints

oof
foo

which is not what I expect.

jarno
  • 738
  • 8
  • 24