Skip to main content
Assume GNU sed so that I can use \n as newline in the replacement strings in the examples.
Link
jarno
  • 738
  • 8
  • 24
edited tags
Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Basic markup
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

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

foo

But if I just

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

it prints

oof foo

oof
foo

which is not what I expect.

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.

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.

example input output
Source Link
jarno
  • 738
  • 8
  • 24
Loading
Source Link
jarno
  • 738
  • 8
  • 24
Loading