LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to compare two number (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-compare-two-number-941771/)

nauman9004 04-26-2012 12:02 AM

How to compare two number
 
How to compare two number in Ksh.For example
0001
0002
0001
0003
0002

nauman9004 04-26-2012 01:12 AM

Sort the number
 
Kindly any one tell me how to sort the number in Kshell

0001
0002
0003
0001
0002

druuna 04-26-2012 01:18 AM

Hi nauman9004 and welcome to LQ,

Bumping your own thread after just an hour is not done (although I do see now that you added a second question), it also has another side-effect: It takes you of the zero reply list (all post with no replies are cycled to give them more exposure).

About your first request: Which 2 numbers need to be compared and how are these numbers entered (by hand, in a file)?

About your second request: Have a look at the sort command.

Hope this helps.

nauman9004 04-26-2012 01:42 AM

Sort the number
 
hello druuna
four numbers are there 0001 , 0002 ,0001,0003 i want to compare these number and sort these numbers these numbers are get from file

druuna 04-26-2012 01:50 AM

Hi,
Quote:

Originally Posted by nauman9004 (Post 4663257)
four numbers are there 0001 , 0002 ,0001,0003 i want to compare these number

You have a file with 4 numbers (4? your other posts show 5 numbers). Do these numbers need to be compared to each other or to something else? Please tell us in more details what you want/need.

Quote:

and sort these numbers these numbers are get from file
Already answered this one: Look at the sort command (man sort for details and options).

Hope this helps.

whizje 04-26-2012 01:53 AM

If the numbers are on separate lines you can use
Code:

sort -n filename
if they are on one line separated by , you must first change the , to a newline
Code:

cat filename | tr ',' '\n' | sort -n

nauman9004 04-26-2012 02:20 AM

Quote:

Originally Posted by druuna (Post 4663265)
Hi,
You have a file with 4 numbers (4? your other posts show 5 numbers). Do these numbers need to be compared to each other or to something else? Please tell us in more details what you want/need.
Already answered this one: Look at the sort command (man sort for details and options).

Hope this helps.

Firstly compare these numbers then sort it.These four or five or six numbers limit is not there.

acid_kewpie 04-26-2012 02:24 AM

well you've already been told about sort. What do you mean by comparing? just comparing two numbers doesn't *do* anything...

nauman9004 04-26-2012 02:47 AM

thanks whizje for sorting it is okay

Tinkster 04-26-2012 02:56 AM

And I'll pipe up as the third one to ask: what are you comparing them to?
In which way do you need to compare them?


All times are GMT -5. The time now is 04:18 PM.