I
I
Ilgiz Khamitov2015-03-02 16:27:32
*nix-like systems
Ilgiz Khamitov, 2015-03-02 16:27:32

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

2 answer(s)
S
Sergey, 2015-03-02
@bk0011m

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');

J
jcmvbkbc, 2015-03-02
@jcmvbkbc

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 question

Ask a Question

731 491 924 answers to any question