I use sed to insert text at beginning of a file. But sed inserts a newline after my text that I do not need. For example, I want to insert "foo" at the beginning of my file:
> cat myfile
This is first line.
> sed -i '1i\foo' myfile
> cat myfile
foo
This is first line.
Instead I want myfile to look like this after insert:
Sorry, I was forgetting the part of adding only in first line,
Try with:
echo "This is first line.
This is second line.
This is third line." | sed '1 s/\(^[A-Z]\)/foo\1/'
fooThis is first line.
This is second line.
This is third line.