1

I want to add multiple lines after matching a pattern. So from

Pattern:
bla

to

Pattern:
    line1-from-file1
    line2-from-file1
bla

I ran something like this sed '/Pattern/r file1' file2 but it gave:

Pattern:
line1-from-file1
line2-from-file1
bla
Cyrus
  • 84,225
  • 14
  • 89
  • 153
Hud
  • 301
  • 1
  • 12

1 Answers1

1

This might work for you (GNU sed):

sed 's/^/    /' file1 | sed '/pattern/r /dev/stdin' file2

Pipe a sed amended file1 into a second invocation of sed matching pattern in file2.

The ameliorated file1 is presented as /dev/stdin and added to the second sed by way of the r command.

potong
  • 55,640
  • 6
  • 51
  • 83