Martin Mielke wrote:
Dear all,
how can I append a text header to a plain-text file (source code) without deleting what's been already there?
I guess, the clue resides on 'man sed' but some examples will be much appreciated.
You can do it with the sed insert command, but a temporary file cannot be avoided. Create a script (called for example `insert_header') with the following contents: #!/usr/bin/sed -f 1i\ First line\ Second line The so called "hash-bang" (#!) invokes sed with the remainder of the script as commands for sed. Make it executable: chmod u+x insert_header Invoke it with the file to read as the argument: insert_header my_file Note that the output goes to stdout. To make it complete, do something like: insert_header my_file > tmp_file && mv tmp_file my_file The `&&' makes sure that the second command (`mv') only takes place if the first command is succesful. It pays off to always take such a precation. After all, it is hardly any trouble, but it could safe you a lot of grief. Good luck. Paul.