LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 12-19-2010, 09:48 AM   #1
saheervc
LQ Newbie
 
Registered: Mar 2009
Posts: 3
Blog Entries: 1

Rep: Reputation: 0
Sort a data according to a given criteria


Im struck with the following problem.
I have a data file with following data

1 1 1 1 3
1 1 1 2 2
1 1 1 3 1
1 1 2 1 2
1 1 2 2 1
1 1 3 1 1
1 2 1 1 2
1 2 1 2 1
1 2 2 1 1
1 3 1 1 1
2 1 1 1 2
2 1 1 2 1
2 1 2 1 1
2 2 1 1 1
3 1 1 1 1


(sum of each row is always same and number is either 1,2 or 3)
I would like to arrange the data in the following way
1 1 1 1 3
1 1 1 3 1
1 1 3 1 1
1 3 1 1 1
3 1 1 1 1

1 1 1 2 2
1 1 2 2 1
1 2 2 1 1
2 2 1 1 1
2 1 1 1 2
1 1 2 1 2
1 2 1 1 2
2 1 1 2 1
2 1 2 1 1
.....

(ie, i have to arrange the row based on whether
* one number is different and all other 4 are same
* two numbers are different and all other 3 are same
....
....
* all 5 numbers are different
* all 5 numbers are same

(I have bigger data that needs to check all the above conditions)

Im a newbie.
Can some one help me to get a code for the above problem
(either a shell code or a c-program)

Please help
Thanks in advance

Last edited by saheervc; 12-19-2010 at 09:50 AM.
 
Old 12-19-2010, 10:19 AM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 804

Rep: Reputation: 186Reputation: 186
Think of the logic if you had to do it manually (paper and pencil, no computer).

Scan the rows and count the number of ones, twos and threes in each row. Based on the result, prefix the result to each row. Sort the data. Drop the prefixed part.

I leave u to work out the details.

Last edited by AnanthaP; 12-19-2010 at 10:21 AM.
 
1 members found this post helpful.
Old 12-19-2010, 12:03 PM   #3
saheervc
LQ Newbie
 
Registered: Mar 2009
Posts: 3
Blog Entries: 1

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by AnanthaP View Post
Think of the logic if you had to do it manually (paper and pencil, no computer).

Scan the rows and count the number of ones, twos and threes in each row. Based on the result, prefix the result to each row. Sort the data. Drop the prefixed part.

I leave u to work out the details.
A bit tedious. But works.
Thanks for your advice
.
 
  


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
Can I sort by different criteria? bioinformatics_guy Linux - Newbie 3 09-29-2008 08:37 AM
data file sort problem johnpaulodonnell Linux - Newbie 2 05-01-2008 09:10 AM
some sort of data analyzer exkor5000 Linux - Software 2 07-07-2006 10:52 AM
Redhat Data Sort eivets Linux - Software 3 03-22-2005 03:52 PM


All times are GMT -5. The time now is 04:54 AM.

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