LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   arrange in increasing order (https://www.linuxquestions.org/questions/linux-newbie-8/arrange-in-increasing-order-4175444539/)

sonia102d 01-07-2013 02:06 PM

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

colucix 01-07-2013 02:13 PM

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.

sonia102d 01-07-2013 02:25 PM

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.

colucix 01-07-2013 02:38 PM

Quote:

Originally Posted by sonia102d (Post 4864845)
>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?

sonia102d 01-07-2013 02:47 PM

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

colucix 01-07-2013 03:22 PM

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



All times are GMT -5. The time now is 05:19 PM.