开发者

Bash, sort after using tail

开发者 https://www.devze.com 2023-02-11 13:21 出处:网络
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 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

精彩评论

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