How do I execute any command editing its file (argument) "in place" using bash?

I have a documents temp.txt, that I intend to arrange with the sort command in bash.

I desire the arranged outcomes to change the initial documents.

This does not benefit instance (I get a vacant documents) :

sortx temp.txt > temp.txt

Can this be carried out in one line without considering replicating to short-lived files?


EDIT: The -o alternative is really trendy for sort. I made use of sort in my inquiry as an instance. I face the very same trouble with various other commands:

uniq temp.txt > temp.txt.

Is there a far better basic remedy?

111
2022-07-25 20:40:24
Source Share
Answers: 4
sort temp.txt -o temp.txt
173
2022-07-25 21:45:13
Source

Use the argument --output= or -o

Just tried out FreeBSD:

sort temp.txt -otemp.txt
1
2022-07-25 21:39:22
Source

If you demand making use of the sort program, you need to make use of a intermediate documents - - I do not assume sort has an alternative for sorting in memory. Any kind of various other method with stdin/stdout will certainly fall short unless you can assure that the barrier dimension for type is stdin allows sufficient to fit the whole documents.

Edit: embarassment on me. sort temp.txt -o temp.txt functions superb.

0
2022-07-25 21:39:18
Source

Many have actually stated the - o alternative. Below is the male web page component.

From the male page:

   -o output-file
          Write output to output-file instead of to the  standard  output.
          If  output-file  is  one of the input files, sort copies it to a
          temporary file before sorting and writing the output to  output-
          file.
4
2022-07-25 20:51:15
Source