LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-26-2012, 01:02 AM   #1
nauman9004
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Rep: Reputation: Disabled
How to compare two number


How to compare two number in Ksh.For example
0001
0002
0001
0003
0002
 
Old 04-26-2012, 02:12 AM   #2
nauman9004
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Sort the number

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

0001
0002
0003
0001
0002
 
Old 04-26-2012, 02:18 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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.
 
Old 04-26-2012, 02:42 AM   #4
nauman9004
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
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
 
Old 04-26-2012, 02:50 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,
Quote:
Originally Posted by nauman9004 View Post
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.
 
Old 04-26-2012, 02:53 AM   #6
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 592

Rep: Reputation: 140Reputation: 140
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
 
Old 04-26-2012, 03:20 AM   #7
nauman9004
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
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.
 
Old 04-26-2012, 03:24 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
well you've already been told about sort. What do you mean by comparing? just comparing two numbers doesn't *do* anything...
 
Old 04-26-2012, 03:47 AM   #9
nauman9004
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
thanks whizje for sorting it is okay
 
Old 04-26-2012, 03:56 AM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I compare floating number in a shell script? abefroman Programming 34 10-12-2016 09:09 AM
[SOLVED] Compare array index number against element in bash rewtnull Programming 10 11-01-2011 03:53 PM
how to compare float number in shell program olivia dunham Linux - Newbie 1 08-23-2011 04:39 AM
how to compare the value is number or null in IF statement p_raju General 10 10-15-2008 01:52 AM
how to compare a variable with a number? pdklinux79 Linux - Newbie 2 06-10-2008 08:02 PM


All times are GMT -5. The time now is 07:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration