Help in sorting echo command

Hi,

I have a simple question on bash.

If i printed out something like below

echo -e $q"\t\t\t"$r"\t\t\t"$s"\t\t\t"$u"\t\t\t" |sort -r >>test.txt

It cant able to sort the $q value. I tried on -nr option but still the same. For your info, the $q value is actually a floating point. I would like to sort it accordingly.

Please advise. Thanks.

If I understand your question correctly Echo is processing one line at a time so you are sorting one line then outputting it to a file which really has no effect with the sort.

Create the file then sort it with sort -rn -o test.txt test.txt

eg test.txt
13.3 b
12.3 a
10.344 c
10.3 4

sort -rn test.txt
13.3 b
12.3 a
10.344 c
10.3 4

Hi,

I made a mistake earlier. It should be sorting on the fourth field rather than the first field.

echo -e $q"\t\t\t"$r"\t\t\t"$s"\t\t\t"$u"\t\t\t" >>test.txt

means i wanted to sort $u.

Input file:

62 5377 143 0.02590
661 0 0 0
60 5377 143 0.02590
659 5377 143 0.02590
658 5377 143 0.02590
657 0 0 0
56 200 0 0.000000
55 5377 143 0.02590
654 0 0 0
53 5377 143 0.02590
652 0 0 0
51 0 0 0

Output line
661 0 0 0
657 0 0 0
654 0 0 0
652 0 0 0
51 0 0 0
62 5377 143 0.02590
60 5377 143 0.02590
659 5377 143 0.02590
658 5377 143 0.02590
55 5377 143 0.02590
53 5377 143 0.02590

Thanks.

Did you read the reply you got already? You're not sorting the file, you are sorting one line at a time, which is not altogether productive. You need to move the sorting to a later stage.