0

I am running sorting script for existing file on ubuntu using bowl script:

sort -r -k 2 -o mayflies.txt

but terminal hangs and not showing anything, however it works without -o but i need to sort in the file and not on screen

1 Answer 1

0

You have not given any input file on which the sort operation will place, thats why the terminal is waiting for the input on STDIN. This is because as if you have not provided any input file, sort will take the input from STDIN.

What you need is, e.g. if the input filename is foo.txt :

sort -r -k 2 -o mayflies.txt foo.txt

This will save the sorted output of foo.txt into mayflies.txt. If you omit the -o mayflies.txt portion the sorted output will be shown on the screen (STDOUT).

On the other hand, if your input and output filenames are meant to be the same file i.e. if you want to save the output to the same file :

sort -r -k 2 -o mayflies.txt mayflies.txt 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .