User richard describes very well what's wrong with your sed
command, and also gives the correct editing script to perform the action you're attempting.
I'm giving an alternative approach which will work in a number of different cases:
The sed
command r
will insert the contents of a file at the current position in the data stream.
Your sed
command line could be written
$ sed '115r /dev/stdin' index.html <data.in
which would have the same effect as sed '115r data.in' index.html
... if the data that you wanted to insert after line 115 was stored in the file data.in
.
/dev/stdin
is a special file that contains whatever is sent through the standard input.
You could also do (with shells supporting "here-strings"):
$ sed '115r /dev/stdin' index.html <<<"my string of stuff"
or
$ sed '115r /dev/stdin' index.html <<<"$myvariableofwonder"
This also works as expected with piping from other commands, obviously:
$ sed -n '1,10p' myfile | sed '115r /dev/stdin' index.html
This will transplant lines 1 to 10 of myfile
into index.html
at line 115.
/dev/stdin
. (for some tools such as gnu awk, it will interpret the/dev/stdin
it self so will work on these legacy systems). – ctrl-alt-delor Jan 19 '17 at 16:32/dev
). – Kusalananda Jan 19 '17 at 16:44/dev/stdin
working in gnu/cygwin now. It did not work when I used it about 10 years ago. – ctrl-alt-delor Jan 19 '17 at 16:51/dev/stdin
? – ctrl-alt-delor Jan 19 '17 at 16:54/dev/stdin
,/dev/stdout
, and/dev/stderr
)". I know of no Unix without them. – Kusalananda Jan 19 '17 at 17:00