sort
具有-o, --output
以文件名作为参数的选项。如果它与输入文件相同,则将结果写入一个临时文件,然后覆盖原始输入文件(与输入文件完全相同sed -i
)。
从GNU sort
信息页面:
`-o OUTPUT-FILE'
`--output=OUTPUT-FILE'
Write output to OUTPUT-FILE instead of standard output. Normally,
`sort' reads all input before opening OUTPUT-FILE, so you can
safely sort a file in place by using commands like `sort -o F F'
and `cat F | sort -o F'. However, `sort' with `--merge' (`-m')
can open the output file before reading all input, so a command
like `cat F | sort -m -o F - G' is not safe as `sort' might start
writing `F' before `cat' is done reading it.
On newer systems, `-o' cannot appear after an input file if
`POSIXLY_CORRECT' is set, e.g., `sort F -o F'. Portable scripts
should specify `-o OUTPUT-FILE' before any input files.
以及来自Open Group基本规范第7期:
-o output
Specify the name of an output file to be used instead of the standard
output. This file can be the same as one of the input files.
insitu
,允许就地使用任何命令。