如何对文件进行原位排序 [英] How to sort a file in-place
问题描述
当我们使用sort file
命令时,
该文件以一种排序的方式显示其内容,如果我不想得到任何种类的输出,而是一个经过排序的文件怎么办?
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?
推荐答案
您可以使用文件重定向来重定向排序后的输出:
You can use file redirection to redirected the sorted output:
sort input-file > output_file
或者您可以使用-o
,--output=FILE
的排序选项来指示相同的输入和输出文件:
Or you can use the -o
, --output=FILE
option of sort to indicate the same input and output file:
sort -o file file
注意:一个常见的错误是试图将输出重定向到相同的输入文件
(例如sort file > file
).这不起作用,因为外壳正在进行重定向(不是 sort(1)程序),并且输入文件(也作为输出)将在给出 sort( 1)安排阅读的机会.
Note: A common mistake is to try to redirect the output to the same input file
(e.g. sort file > file
). This does not work as the shell is making the redirections (not the sort(1) program) and the input file (as being the output also) will be erased just before giving the sort(1) program the opportunity of reading it.
这篇关于如何对文件进行原位排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!