How to sort decimal values in bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to sort decimal values in bash
# 1  
Old 01-21-2008
How to sort decimal values in bash

Hi,

I have a list of values from associative array from 0,..till 1.0000.

I tried various sort options; sort -g, sort -nr but it still couldnt work. In other words, the numbers are not sorted accordingly.

Please help.
Thanks.
# 2  
Old 01-21-2008
How is the array formatted ? Can you show few samples, is this different file ? Look here for pointers, and especially at Example 26-11.

Last edited by sysgate; 01-21-2008 at 09:31 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to compare decimal values in bash?

Hi, I am facing some error while doing the comparision between 2 decimal values in bash. Pl help me out. I have tried using below scripts. But its giving me error. 1)amt=12.3 opn_amt=12.5 var=$(awk 'BEGIN{ print "'$amt'"<"'$opn_amt'" }') if ;then echo "correct" else echo "Wrong"... (3 Replies)
Discussion started by: Siba Tripathy
3 Replies

2. Shell Programming and Scripting

How compare decimal values?

I have 2 files say tp1.txt and tp2.txt having following data cat tp1.txt abc,2.20,IN20 acb,3.15,DN10 bca,3,RD10 cat tp2.txt alv,1.00,IN20 aaa,4.05,DD10 abb,5.50,RD12 i want to compare the values on 2nd field of both the file, if value of first tp1.txt is greater than value... (3 Replies)
Discussion started by: ranabhavish
3 Replies

3. Shell Programming and Scripting

How to sort when there is variable length decimal points.?

Hi Experts, Quick quesion: I want to sort this in the file , but not working, when using # sort file name 305.932 456.470 456.469 456.468 456.467 172.089 456.467 456.466 456.465 111.573 111.578 111.572 111.572 87.175 87.174 75.898 (4 Replies)
Discussion started by: rveri
4 Replies

4. Shell Programming and Scripting

Sort Decimal number in UNIX

Hello Everyone, In one of my script, I would like to sort the decimal numbers. For e.g. If I have numbers like 1.0 1.1 1.2 2.0 2.1 3.0 4.0 5.0 6.0 7.0 7.1 7.10 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 I would like to sort them 1.0 1.1 1.2 2.0 2.1 3.0 4.0 5.0 6.0 7.0 7.1 7.2 7.3 7.4... (3 Replies)
Discussion started by: sachinrastogi
3 Replies

5. UNIX for Dummies Questions & Answers

compare decimal and integer values in if in bash shell

i need to do camparisions like the below. For the case when first=10 and second=9.9 the scripts displays process failed. I need to be able to convert the values to integer before doing the comparision. Like 9.9 should be rounded over to 10 before doing comparision. Please advice how can... (3 Replies)
Discussion started by: nehagupta
3 Replies

6. Shell Programming and Scripting

How to get decimal values ?

Hi All, In my script I've written like this- c=$( expr 100 / 3);echo $c The output coming is 33. but I want to see 33.33, decimal values too. How to get that? Thanks, Naresh (3 Replies)
Discussion started by: NARESH1302
3 Replies

7. Shell Programming and Scripting

how to sort date in decimal values uptp two digits

Hi all, there is a data in a file wich loks likes 00:00:49|24.48| 00:01:49|22.83| 00:02:49|22.07| 00:03:49|20.72| 00:04:49|21.28| 00:05:49|21.22| 00:06:49|21.38| 00:07:49|20.93| 00:08:49|21.27| 00:09:49|20.65| 00:10:49|19.42| 00:11:49|21.93| 00:12:49|20.62| 00:13:49|20.23|... (3 Replies)
Discussion started by: jojo123
3 Replies

8. Shell Programming and Scripting

Evaluating Decimal values

How can I evaluate a decimal value in an if statement? echo "Enter limit:" read limit (enter a decmal value, ie: 2.5) decimallimit=`echo $limit+0|bc|quit` echo $decimallimit if then echo $decimallimit else echo "failed" fi (4 Replies)
Discussion started by: larrys721
4 Replies

9. UNIX for Advanced & Expert Users

Converting Binary decimal coded values to Ascii Values

Hi All, Is there any command which can convert binary decimal coded values to ascii values... i have bcd values like below оооооооооооо0о-- -v - Pls suggest a way to convert this. Thanks, Deepti.Gaur (3 Replies)
Discussion started by: gaur.deepti
3 Replies
Login or Register to Ask a Question