Latest LQ Deal: Linux Power User Bundle
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org Sort a data according to a given criteria
 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

 12-19-2010, 08:48 AM #1 saheervc LQ Newbie   Registered: Mar 2009 Posts: 3 Blog Entries: 1 Rep: 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 08:50 AM.
 12-19-2010, 09:19 AM #2 AnanthaP Member   Registered: Jul 2004 Location: Chennai, India Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC Posts: 877 Rep: 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 09:21 AM. 1 members found this post helpful.
12-19-2010, 11:03 AM   #3
saheervc
LQ Newbie

Registered: Mar 2009
Posts: 3
Blog Entries: 1

Original Poster
Rep:
Quote:
 Originally Posted by AnanthaP 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.
.

 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 Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post bioinformatics_guy Linux - Newbie 3 09-29-2008 07:37 AM johnpaulodonnell Linux - Newbie 2 05-01-2008 08:10 AM exkor5000 Linux - Software 2 07-07-2006 09:52 AM eivets Linux - Software 3 03-22-2005 02:52 PM

LinuxQuestions.org

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

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -