You can't redirect to the same file: the obvious problem with sed "s/\..*//" Filename > Filename
is that the shell opens Filename
for writing (and overwrites it) before the file is read by sed
.
You'd need to redirect output to a different file, delete the original file, and then rename the newly created file the same as the original. Sed, Perl and AWK can do this for you:
sed -i
perl -i
awk -i inplace
Alternatively, you can use sponge
:
sed "s/\..*//" Filename | sponge Filename
sponge
keeps buffering what it receives from standard input, and only then writes it to Filename
.