Skip to main content
added 352 characters in body
Source Link
don_crissti
  • 85.7k
  • 31
  • 234
  • 262

If you need to read in the output of a command, you could use ed as in the linked question, with this variation:

ed -s test.txt <<< $'0r !echo stuff\nw\nq' 

This reads the output of the command echo stuff into test.txt after line zero.


To insert multi-line text before the 1st line via here-doc you'd run

ed -s test.txt <<EOT 1i add some line and some more to the beginning . w q EOT 

The dot signals the end of input-mode which means the last solution assumes your text doesn't contain lines consisting of single dots.

If you need to read in the output of a command, you could use ed as in the linked question, with this variation:

ed -s test.txt <<< $'0r !echo stuff\nw\nq' 

This reads the output of the command echo stuff into test.txt after line zero.

If you need to read in the output of a command, you could use ed as in the linked question, with this variation:

ed -s test.txt <<< $'0r !echo stuff\nw\nq' 

This reads the output of the command echo stuff into test.txt after line zero.


To insert multi-line text before the 1st line via here-doc you'd run

ed -s test.txt <<EOT 1i add some line and some more to the beginning . w q EOT 

The dot signals the end of input-mode which means the last solution assumes your text doesn't contain lines consisting of single dots.

Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266

If you need to read in the output of a command, you could use ed as in the linked question, with this variation:

ed -s test.txt <<< $'0r !echo stuff\nw\nq' 

This reads the output of the command echo stuff into test.txt after line zero.