When we use sort file command,
the file shows its contents in a sorted way what if I don\'t want to get any-kind of output but a sorted file?
Here's an approach which (ab)uses vim:
vim -c :sort -c :wq -E -s "${filename}"
The -c :sort -c :wq portion invokes commands to vim after the file opens. -E and -s are necessary so that vim executes in a "headless" mode which doesn't draw to the terminal.
This has almost no benefits over the sort -o "${filename}" "${filename}" approach except that it only takes the filename argument once.
This was useful for me to implement a formatter directive in a nanorc entry for .gitignore files. Here's what I used for that:
syntax "gitignore" "\.gitignore$"
formatter vim -c :sort -c :wq -E -s