Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question relates to the already asked question How to add text to beginning of file

The answer suggested by Dennis Williamson does the job:

echo 'task goes here' | cat - todo.txt > temp && mv temp todo.txt

In the above, the string task goes here is added to the start of the file.

If the string task goes here is in a file called myfile.txt, then how should i change the command? echo 'myfile.txt'... OR echo myfile.txt... do not do the job.

share|improve this question
up vote 4 down vote accepted
cat myfile.txt todo.txt > temp && mv temp todo.txt

cat con"cat"enates several files. In the original solution, the first file was -, which means "standard input", i.e., whatever is piped into the cat command. Here you have already two named files, namely myfile.txt and todo.txt, so you can just use them as arguments for cat.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .