Skip to content

Instantly share code, notes, and snippets.

@nad2000
Created February 6, 2014 23:35
Show Gist options
  • Save nad2000/8854762 to your computer and use it in GitHub Desktop.
Save nad2000/8854762 to your computer and use it in GitHub Desktop.
How do I add text to the beginning of a file in Bash?
echo 'task goes here' | cat - todo.txt > temp && mv temp todo.txt
# OR
cat <(echo "task goes here") todo.txt > todo_new.txt
# OR
echo -e "task goes here\n$(cat todo.txt)" > todo.txt
# OR
sed -i '1s/^/task goes here\n/' todo.txt
# OR
sed -i '1itask goes here' todo.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment