Hi I want to prepend text to a file. For example I want to add tasks to the beginning of a todo.txt file. I am aware of echo 'task goes here' >> todo.txt but that adds the line to the end of the file (not what I want).
|
| |||
|
feedback
|
or
or
| |||||
feedback
|
|
You can create a new, temporary file.
You might also use | |||||||
feedback
|
|
You cannot insert content at the beginning of a file. The only thing you can do is either replace existing content or append bytes after the current end of file. Any solution to your question then requires a temporary file to be created (on memory or on disk) which will eventually overwrite the original file. Beware not loosing data by preserving the original file while building the new one, should the file system happen to be full during the process. eg:
| ||||
|
feedback
|