LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 01-07-2013, 02:06 PM   #1
sonia102d
LQ Newbie
 
Registered: Sep 2012
Posts: 18

Rep: Reputation: Disabled
Question arrange in increasing order


Hi

i have a sequence which has 30000 strings which looks like this

>string2791 280460
>string654 770561
>string2038 373997
>string8551 15386
>string4098 177229
>string3049 255838
>string8 672382
>string1358 507255
>string1115 578415

i want it to be arranged in order of incremental

>string8 672382
>string654 770561
>string1115 578415
>string1358 507255
>string2038 373997
>string2791 280460
>string3049 255838
>string4098 177229
>string8551 15386

I want to basically know the lowest value in the whole sequence and the highest sequences. Please help.


Thanks
Sonia
 
Old 01-07-2013, 02:13 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Is ">string" the real and unique string in the first field of the file? If it is, a simple
Code:
sort -k1.8n file
should do the trick.
 
Old 01-07-2013, 02:25 PM   #3
sonia102d
LQ Newbie
 
Registered: Sep 2012
Posts: 18

Original Poster
Rep: Reputation: Disabled
Thanks for the quick help.The >string" is a unique string in the first field of the file.

i tried that code but its giving me a sequence like this

>string21099 1028
>string21199 1020
>string21299 1013
>string21399 1007
>string21499 1001
>string1 3094459
>string9 2265554
>string8 2287989
>string7 23658

they are getting arranged in incremental order but in sets.
Is there anything we could try?
Thanks.
 
Old 01-07-2013, 02:38 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by sonia102d View Post
>string21099 1028
>string21199 1020
>string21299 1013
>string21399 1007
>string21499 1001
>string1 3094459
>string9 2265554
>string8 2287989
>string7 23658

they are getting arranged in incremental order but in sets.
Weird. If I get your output and run the sort command it prints out the desired result:
Code:
$ cat > file
>string21099 1028
>string21199 1020
>string21299 1013
>string21399 1007
>string21499 1001
>string1 3094459
>string9 2265554
>string8 2287989
>string7 23658
$ sort -k1.8n file
>string1 3094459
>string7 23658
>string8 2287989
>string9 2265554
>string21099 1028
>string21199 1020
>string21299 1013
>string21399 1007
>string21499 1001
What am I missing?
 
Old 01-07-2013, 02:47 PM   #5
sonia102d
LQ Newbie
 
Registered: Sep 2012
Posts: 18

Original Poster
Rep: Reputation: Disabled
Question

The cat command takes a long time to work in my system....
may be becoz my sequence is pretty big.I have 21513 sequences of this format.
May be its that reason that its doing sorting in block?

I am not sure,i could be completely wrong. but i use the following command :
sort -k1.8n reads_original.txt >reads_new.txt
 
Old 01-07-2013, 03:22 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I tested it on a file with 21513 sequences and it works as expected. Trying to figure out what's going on, please can you test this awk code to see if it makes a correct sorting?
Code:
awk '
{
  m = $1 
  sub(/^[^0-9]+/,"",m)  
  p[m] = $0
  s[++c] = m + 0
}

END {
  n = asort(s)  
  for (i = 1; i <= n; i++)
    print p[s[i]]
}' reads_original.txt
 
  


Reply



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
[SOLVED] Arrange output by frequency of occurrence oliviaxinw Linux - Newbie 6 08-23-2012 05:09 PM
[SOLVED] cant arrange desktop icons the way i want on kde? jason_lee_91 Linux - Newbie 3 04-24-2011 02:56 PM
How to Auto-arrange Desktop Icons malekmustaq Linux - Newbie 2 08-16-2010 06:50 AM
How to arrange NIC accordingly ? makubex Linux - Networking 2 11-29-2007 10:48 PM
KDE 3.3 Menus - arrange alphabetically equinox SUSE / openSUSE 9 11-28-2005 06:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:53 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
Open Source Consulting | Domain Registration