So, I want to insert test in .txt but when I try
type file1.txt >> file2.txt
sort file1 | uniq >> sorted
It is not possible to write to the start of the file. You can only replace the file content with content provided or append to the end of a file. So if you need to add the sorted output in front of the
sorted file, you have to do it like that:
mv sorted sorted.old sort file1 | uniq > sorted cat sorted.old >> sorted rm sorted.old
This is not a limitation of the shell but of the file APIs of pretty much every existing operating system. The size of a file can only be changed at the end, so you can increase it, in that case the file will grow at the end (all content stays as it is but now there is empty space after the content) or you can truncate it (in that case content is cut off at the end). It is possible to copy data around within a file but there exists no system function to do that, you have to do it yourself and this is almost as inefficient as the solution shown above.