Search This Blog

shell script: insert line at the beginning of a text file

On linux:
sed -i -e '1s/^/Here is the first line.\n&/g' file.txt



On Mac OS, the above does NOT work. You have to use the following instead:
sed -i -e '1s/^/Here is the first line.\'$'\n/g' file.txt

see also

No comments:

Post a Comment