Help in sorting echo command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in sorting echo command
# 1  
Old 03-27-2008
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.
# 2  
Old 03-28-2008
Quote:
Originally Posted by ahjiefreak
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
# 3  
Old 03-28-2008
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.
# 4  
Old 03-28-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to echo command successful if command is executed successfully

Hello, I have written a command n shell script : srvctl relocate service -d t1 -s s1 -i i1 -t t1 -f If the above command executes successfully without error I need to echo "Service relocated successfully and If it errors out I need to trap the errors in a file and also need to make... (1 Reply)
Discussion started by: Vishal_dba
1 Replies

2. UNIX for Dummies Questions & Answers

Help me with Echo Command

Hi All I have the big statement which needs to be appended to the file MANUALLY without opening the file. So, i tried with echo command echo " failure ( 4446): for host xx.xx.xx.xxx trying to GET /index.html, wl-proxy reports: exception occurred for backend host 'xx.xx.xxx.xx/12210/12210':... (11 Replies)
Discussion started by: Kalaiela
11 Replies

3. Shell Programming and Scripting

sorting output of echo

can someone please tell me who to sort the numerical output of echo? UIO="8180 0 0 0 0 0 0 0 0 0 0 48240 48240 48240 48240 48240 48240 0 0 0 0 0 0 0 48300 0 0 0 48300" echo $UIO | sort -n This doesn't workk. it does not sort the numbers from smallest to highest. any ideas? (2 Replies)
Discussion started by: SkySmart
2 Replies

4. Shell Programming and Scripting

Echo Command Help

Hi All I want to use the echo command to had some lines to a file but the lines i want to have contain " and ; here is my command system("echo user_pref("accessibility.typeaheadfind.flashBar", 0); > $profile"); but i think there are too many " and so it barfs n e ideas thanks A (5 Replies)
Discussion started by: ab52
5 Replies

5. UNIX for Dummies Questions & Answers

What will echo $$ command give

Hi I tried giving the following command echo $$a I got an output like 32178a Can some one please explain why echo $$ is returning 32178 Thanks in advance (6 Replies)
Discussion started by: Sri3001
6 Replies

6. Shell Programming and Scripting

What does following echo command do?

Can anybody tell me what does following command do? # echo gsoc1 | ./configure_cmd.sh Regards, akash mahakode (1 Reply)
Discussion started by: akash_mahakode
1 Replies

7. UNIX for Dummies Questions & Answers

Help with Data Sorting Command

Hi, I have a problem on data sorting, example my file as below: 123 123/789 aaa bbb ccc ddd (adf) 112 112/123 aaa bbb ccc (ade) 102 1a3/7g9 (adf)03 110 12b/129 aaa bbb ccc ddd fff(a8f)03 117 42f/8c9 aaa bbb ccc ddd (adf) 142 120/tyu fff... (7 Replies)
Discussion started by: 793589
7 Replies

8. UNIX for Dummies Questions & Answers

creating a command and sorting???

How do you write a command line that displays the number of files in the working directory with names that end with the letter S? Thanks ---------- Post updated at 09:34 PM ---------- Previous update was at 09:33 PM ---------- for unix sorry (1 Reply)
Discussion started by: jorogon0099
1 Replies

9. UNIX for Dummies Questions & Answers

Echo command with $$ $# $@

Hi, Good morning. Would you please explain to me what does it mean by the following command. echo "$$ $# $@" >> /opt/ftp_generic_send.log I know that something is being directed to log file, but not sure what exactly mean by those $$ and $# and $@ means. Thank you for your help.... (3 Replies)
Discussion started by: howdy
3 Replies

10. UNIX for Advanced & Expert Users

comm command in sorting IP

i have 2 files that contains a sorted list of IP addresses. file_A contains a list of all IPs file_B contains only around 50% of what is in file_A. I tried to execute comm -23 file_A file_B > file_C to get the difference. My objective is to put all the IPs that are in file_A but not... (1 Reply)
Discussion started by: tads98
1 Replies
Login or Register to Ask a Question