0
red    
blue    
water    
gray    
white

I want to use

sed '/blue/,/gray/!b;//!d;/blue/r file2' file1

As mentioned in this Replace text between two lines with contents of a file stored in a variable in sed thread

But instead of file2 i want to enter new string directly in command. Can any one show me how to do that.

Inian
  • 80,270
  • 14
  • 142
  • 161
  • You mean you want to apply the `sed` operation on a output of a command? Can you explain more? – Inian Dec 08 '17 at 08:00
  • @Inian No. I don't want to get new content from `file2` but instead directly put string(new text) in this `sed '/blue/,/gray/!b;//!d;/blue/r file2' file1` I dont know the syntax for that – HardikHarpal Dec 08 '17 at 08:04

1 Answers1

1

You can use this sed:

sed '/blue/,/gray/!b;//!d;/blue/a SOMEDATA' file

From man sed:

a \
  text

Append text, which has each embedded newline preceded by a backslash.

Another example:

$ sed '/blue/,/gray/!b;//!d;/blue/a \
> LINE 1 \
> LINE 2 \
> LINE 3' file

red    
blue    
LINE 1 
LINE 2 
LINE 3
gray    
white
sat
  • 14,589
  • 7
  • 46
  • 65