unixcommand-lineutilitiesprepend

Unix command to prepend text to a file


Is there a Unix command to prepend some string data to a text file?

Something like:

prepend "to be prepended" text.txt

Solution

  • sed -i.old '1s;^;to be prepended;' inFile
    

    If you want to add a new line to the beginning of the file, you need to add \n on the replacement as in:

    sed -i.old '1s;^;to be prepended\n;' inFile