There’s a trap almost everybody walks into once: you want a file sorted, so you type sort list.txt > list.txt. The result is an empty file. The shell opens and truncates list.txt for the redirect before sort has read a single line.
Sort has its own way around that. With -o you name the output file, and sort writes it only after it has read all of its input:
sort -o list.txt list.txt
The GNU manual says it plainly: because sort normally reads everything before it opens the output file, sort -o F F is a way to sort a file in place. The same goes for cat F | sort -o F.
I like it for small lists I keep by hand, like a file of hostnames or a list of container names I check on my Unraid server. Add a line at the end, then put the file back in order in one go:
echo "jellyfin" >> containers.txt && sort -o containers.txt containers.txt
It also mixes with all the other sort options, so sort -t, -k2,2 -o data.csv data.csv works the same way. Note that this trick belongs to sort. Most other filters, like cut, tr or grep, have no such option, and with them a redirect to the same file still wipes it.
The caveat comes straight from the manual too. Sorting in place means the original is gone the moment sort starts writing. If the machine crashes or sort hits an I/O error halfway, you can lose data. For anything that matters, my advice is to write to a new file first and move it over the old one when sort finishes without an error:
sort data.csv > data.sorted && mv data.sorted data.csv
Further reading: GNU sort invocation