590
Comment: ed sucks
|
681
|
Deletions are marked like this. | Additions are marked like this. |
Line 4: | Line 4: |
To do it in 2 commands with sed: sed "1iTEXTTOPREPEND" filename > tmp mv tmp filename |
How do I prepend a text to a file (the opposite of >>)?
You cannot do it with bash redirections alone; the opposite of >> does not exist....
To do it in 2 commands with sed: sed "1iTEXTTOPREPEND" filename > tmp mv tmp filename
To insert content at the beginning of a file, you can use an editor:
ex file << EOF 0a header line 1 header line 2 . w EOF
ex will also add a newline character to the end of the file if it's missing.
Or you can rewrite the file, using things like:
{ echo line; cat file ;} >tmpfile && mv tmpfile file echo line | cat - file > tmpfile && mv tmpfile file
or lots of other solutions.