user616731
user616731

Reputation: 23

Bash, sort after using tail

I perform 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

Upvotes: 0

Views: 2651

Answers (2)

Dennis Williamson
Dennis Williamson

Reputation: 360153

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.

Upvotes: 1

John Lewis
John Lewis

Reputation: 722

try:

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

Upvotes: 7

Related Questions