Different ways to add a string:
(echo 'line to prepend';cat file)|sponge file sed -i '1iline to prepend' file # GNU sed -i '' $'1i\\\nline to prepend\n' file # BSD printf %s\\n 0a 'line to prepend' . w|ed -s file perl -pi -e 'print"line to prepend\n"if$.==1' file
Different ways to add a file:
cat file_to_prepend file|sponge file { rm file;cat file_to_prepend ->file; }<file sed -i '1{h;s/.*/cat file_to_prepend/ep;g}' file # GNU printf %s\\n '0r file_to_prepend' w|ed -s file sed -i -e 1rfile_to_prepend -e '1{h;d}' -e '2{x;G}' file
source share