Insert a word in the first line of the file
With GNU sed
:
sed -i '1s/^/insertedtext/' file
This replaces the beginning of the first line with the inserted text. -i
replaces the text in file
rather than sending the modified text to the standard output.
If portability across unices is a concern, use ed
:
ed file <<END
1s/^/insertedtext/
w
q
END
POSIX one:
$ { printf %s insertedtext; cat <./input_file; } >/tmp/output_file
$ mv -- /tmp/output_file ./input_file