Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.