Answer the question
In order to leave comments, you need to log in
How to overwrite a UNIX file?
There is a code, you need to overwrite the result in the same file exec ('sort -u -b -n 1.txt > uTest_1.txt');
Now overwrites in uTest_1.txt, but you need to 1.txt
Answer the question
In order to leave comments, you need to log in
And so:
-o - this specifies the file where to save the result. There will be nothing on the screen
or something like this:
exec ('sort -u -b -n 1.txt > uTest_1.txt && mv uTest_1.txt 1.txt');
In the general case - no way, just write to a temporary file, and then rename it.
In a special case of sort, you can use -o, which is explicitly stated here that the name of the specified file can be the same as the name of one of the input files. (But not always, in particular, with the -m switch, gnu sort may overwrite the input file before it is read).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question