How to prepend contents of a file to another

2

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.

detraveller

Posted 2013-04-22T12:26:01.393

Reputation: 585

Answers

6

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.

Uwe

Posted 2013-04-22T12:26:01.393

Reputation: 1 043