开发者

Bash, sort after using tail

I pe开发者_StackOverflow中文版rform a tail on 3 files and then create a new file, when I go to sort this new file it says it cannot be accessed. So in the code $a,$b and $c are text files. So how can i get this to sort the new file?

tail -q -n -5 $a $b $c > file.txt
sort file.txt -o file.txt


try:

tail -q -n -5 $a $b $c | sort > file.txt


What version of sort? For GNU coreutils 7.4 it works for me.

If you were doing

sort file.txt > file.txt

it wouldn't work because the redirection would truncate the file before sort read from it. However, when I do an strace, it reveals that sort -o doesn't write to the output file until the end.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜