GNU sed knows the -i option, which does in-place data editing.
When performing the operation file1 > file1 , what actually happens is that the file is opened and truncated by the shell before , the program (which receives this name as an argument) comes with it, reading something from it.
Update
The sed man page specifies the following in the -i option (thanks to Delan for mentioning):
-i[SUFFIX], --in-place[=SUFFIX] edit files in place (makes backup if extension supplied)
Marcus borkenhagen
source share