Another way to use GNU sed:
sed -i -e '1rfile1.txt' -e '1{h;d}' -e '2{x;G}' file2.txt
I.e:
- On line 1, add the contents of
file1.txt
- In line 1, copy the template space to save a space, and delete the template space
- On line 2, exchange the contents of the hold space and the template and add the hold space to the drawing space
The reason is a bit complicated because the r
command adds content and line 0 is not addressed, so we must do this on line 1 by moving the contents of the original line to the side and then returning it after adding the contents of the file.
source share