The following inserting file method for sed
used to be working, even before last line, but not any more. Is it a bug in the current sed
?
Demo of inserting file method with sed:
mkdir /tmp/test
printf '%s\n' {1..3} > /tmp/test/f1
printf '%s\n' {one,two,three,four,five,six,seven,eight,nine,ten} > /tmp/test/f2
$ cat /tmp/test/f2 | sed -e "/nine/r /tmp/test/f1" -e //N
one
two
three
four
five
six
seven
eight
1
2
3
nine
ten
$ head -9 /tmp/test/f2 | sed -e "/nine/r /tmp/test/f1" -e //N
one
two
three
four
five
six
seven
eight
nine
1
2
3
$ cat /tmp/test/f2 | sed -e "/ten/r /tmp/test/f1" -e //N
one
two
three
four
five
six
seven
eight
nine
ten
1
2
3
$ sed --version
GNU sed version 4.2.1
...
I.e., the inserting file before the line method works everywhere except the last line. It used to be working before. Is it a bug in the current sed
?
Thanks
Best Answer
Since you're on
gnu sed
you could useon the la
$
t line:With
ed
(replace,p
withw
if you want to edit-in-place):or
When
ed
readsfile
the current address is set to the la$
t line.-
(or-1
) sets the current address to one line before (i.e.$-1
) andr
reads ininsert.txt
to after the current line.,p
prints the content of the text buffer (as I said, replace withw
to save changes) andq
quits editor.