3

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.

1 Answer 1

7
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.

0

You must log in to answer this question.

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