How to overwrite a UNIX file?

There is a code you need to overwrite the result on the same file

exec ('sort-u-b-n 1.txt > uTest_1.txt');

Now overwrites in uTest_1.txt and you need to 1.txt
September 19th 19 at 00:12
2 answers
September 19th 19 at 00:14
And so:
exec ('sort-u-b-n 1.txt -o 1.txt');
-o - that specify the file where to save the result. On the screen nothing will happen

or this:
exec ('sort-u-b-n 1.txt > uTest_1.txt && mv uTest_1.txt 1.txt');
and what to do about the pipeline? it seems to me that it is more correct to use ; or && - arlene_Lebsa commented on September 19th 19 at 00:17
: Yes, was in a hurry... Corrected )) - cullen.Jast40 commented on September 19th 19 at 00:20
September 19th 19 at 00:16
In the General case -- can only write to a temporary file and then rename it.
In the particular case of sort you can use -o, which here explicitly says that the name of the file to match the name of one of the input files. (But not always, particularly in the presence of the-m switch to gnu sort may overwrite the input file before it is read).

Find more questions by tags * nix-like systems