Skip to main content
added 40 characters in body; edited title
Source Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k

sort Sort text by specific location on each line

Hi I've worked out a solution to this, but I want to know if there is a more direct and simple way of doing it.

What I want to achieve is sorting lines of text by a specific point in the text (the lines of text have no spaces or columns). I've worked out a solution to this, but I want to know if there is a more direct and simple way of doing it.

My current method for this is to cause a break i.e. make a new column at the same place on every line (just before the point I want to sort by - this being Sn_L001_Rn) and then sort by that column, and then join the two columns back together. this works but it seems overly complicated and clunky. I've seen posts on making a score system with awk, but as mine are going to go to at least 96, then this seems lengthy. also i've seen sqlite might be applicable, but this also seems equally lengthy. I apologise if this question has already been asked, but so far I have failed to find a simple method to resolve it.

hereHere is some example Input and desired outputinput:
#INPUT SOON_S2_L001_R1_001.txt
SOON_S2_L001_R2_001.txt
HELLO_S4_L001_R1_001.txt
HELLO_S4_L001_R2_001.txt
BASH_S1_L001_R1_001.txt
BASH_S1_L001_R2_001.txt
WORLD_S3_L001_R1_001.txt
WORLD_S3_L001_R2_001.txt

#OUTPUT

SOON_S2_L001_R1_001.txt    
SOON_S2_L001_R2_001.txt    
HELLO_S4_L001_R1_001.txt    
HELLO_S4_L001_R2_001.txt    
BASH_S1_L001_R1_001.txt    
BASH_S1_L001_R2_001.txt    
WORLD_S3_L001_R1_001.txt    
WORLD_S3_L001_R2_001.txt    

BASH_S1_L001_R1_001.txt
BASH_S1_L001_R2_001.txt
SOON_S2_L001_R1_001.txt
SOON_S2_L001_R2_001.txt
WORLD_S3_L001_R1_001.txt
WORLD_S3_L001_R2_001.txt
HELLO_S4_L001_R1_001.txt
HELLO_S4_L001_R2_001.txtDesired output:

BASH_S1_L001_R1_001.txt    
BASH_S1_L001_R2_001.txt    
SOON_S2_L001_R1_001.txt    
SOON_S2_L001_R2_001.txt    
WORLD_S3_L001_R1_001.txt    
WORLD_S3_L001_R2_001.txt    
HELLO_S4_L001_R1_001.txt    
HELLO_S4_L001_R2_001.txt    

toTo add further complexity, in a situation where the is more than 1 of the same Sn then iI would like it to take into account the name (though iI think this may be resolvable using flags in sortsort).

sort text by specific location on each line

Hi I've worked out a solution to this, but I want to know if there is a more direct and simple way of doing it.

What I want to achieve is sorting lines of text by a specific point in the text (the lines of text have no spaces or columns).

My current method for this is to cause a break i.e. make a new column at the same place on every line (just before the point I want to sort by - this being Sn_L001_Rn) and then sort by that column, and then join the two columns back together. this works but it seems overly complicated and clunky. I've seen posts on making a score system with awk, but as mine are going to go to at least 96, then this seems lengthy. also i've seen sqlite might be applicable, but this also seems equally lengthy. I apologise if this question has already been asked, but so far I have failed to find a simple method to resolve it.

here is some example Input and desired output:
#INPUT SOON_S2_L001_R1_001.txt
SOON_S2_L001_R2_001.txt
HELLO_S4_L001_R1_001.txt
HELLO_S4_L001_R2_001.txt
BASH_S1_L001_R1_001.txt
BASH_S1_L001_R2_001.txt
WORLD_S3_L001_R1_001.txt
WORLD_S3_L001_R2_001.txt

#OUTPUT

BASH_S1_L001_R1_001.txt
BASH_S1_L001_R2_001.txt
SOON_S2_L001_R1_001.txt
SOON_S2_L001_R2_001.txt
WORLD_S3_L001_R1_001.txt
WORLD_S3_L001_R2_001.txt
HELLO_S4_L001_R1_001.txt
HELLO_S4_L001_R2_001.txt

to add further complexity, in a situation where the is more than 1 of the same Sn then i would like it to take into account the name (though i think this may be resolvable using flags in sort)

Sort text by specific location on each line

What I want to achieve is sorting lines of text by a specific point in the text (the lines of text have no spaces or columns). I've worked out a solution to this, but I want to know if there is a more direct and simple way of doing it.

My current method for this is to cause a break i.e. make a new column at the same place on every line (just before the point I want to sort by - this being Sn_L001_Rn) and then sort by that column, and then join the two columns back together. this works but it seems overly complicated and clunky. I've seen posts on making a score system with awk, but as mine are going to go to at least 96, then this seems lengthy. also i've seen sqlite might be applicable, but this also seems equally lengthy. I apologise if this question has already been asked, but so far I have failed to find a simple method to resolve it.

Here is some example input:

SOON_S2_L001_R1_001.txt    
SOON_S2_L001_R2_001.txt    
HELLO_S4_L001_R1_001.txt    
HELLO_S4_L001_R2_001.txt    
BASH_S1_L001_R1_001.txt    
BASH_S1_L001_R2_001.txt    
WORLD_S3_L001_R1_001.txt    
WORLD_S3_L001_R2_001.txt    

Desired output:

BASH_S1_L001_R1_001.txt    
BASH_S1_L001_R2_001.txt    
SOON_S2_L001_R1_001.txt    
SOON_S2_L001_R2_001.txt    
WORLD_S3_L001_R1_001.txt    
WORLD_S3_L001_R2_001.txt    
HELLO_S4_L001_R1_001.txt    
HELLO_S4_L001_R2_001.txt    

To add further complexity, in a situation where the is more than 1 of the same Sn then I would like it to take into account the name (though I think this may be resolvable using flags in sort).

added 196 characters in body
Source Link
Giles
  • 907
  • 7
  • 20

Hi I've worked out a solution to this, but I want to know if there is a more direct and simple way of doing it.

What I want to achieve is sorting lines of text by a specific point in the text (the lines of text have no spaces or columns).

My current method for this is to cause a break i.e. make a new column at the same place on every line (just before the point I want to sort by - this being Sn_L001_Rn) and then sort by that column, and then join the two columns back together. this works but it seems overly complicated and clunky. I've seen posts on making a score system with awk, but as mine are going to go to at least 96, then this seems lengthy. also i've seen sqlite might be applicable, but this also seems equally lengthy. I apologise if this question has already been asked, but so far I have failed to find a simple method to resolve it.

here is some example Input and desired output:
#INPUT SOON_S2_L001_R1_001.txt
SOON_S2_L001_R2_001.txt
HELLO_S4_L001_R1_001.txt
HELLO_S4_L001_R2_001.txt
BASH_S1_L001_R1_001.txt
BASH_S1_L001_R2_001.txt
WORLD_S3_L001_R1_001.txt
WORLD_S3_L001_R2_001.txt

#OUTPUT

BASH_S1_L001_R1_001.txt
BASH_S1_L001_R2_001.txt
SOON_S2_L001_R1_001.txt
SOON_S2_L001_R2_001.txt
WORLD_S3_L001_R1_001.txt
WORLD_S3_L001_R2_001.txt
HELLO_S4_L001_R1_001.txt
HELLO_S4_L001_R2_001.txt

to add further complexity, in a situation where the is more than 1 of the same Sn then i would like it to take into account the name (though i think this may be resolvable using flags in sort)

Hi I've worked out a solution to this, but I want to know if there is a more direct and simple way of doing it.

What I want to achieve is sorting lines of text by a specific point in the text (the lines of text have no spaces or columns).

My current method for this is to cause a break i.e. make a new column at the same place on every line (just before the point I want to sort by - this being Sn_L001_Rn) and then sort by that column, and then join the two columns back together. this works but it seems overly complicated and clunky. I've seen posts on making a score system with awk, but as mine are going to go to at least 96, then this seems lengthy. also i've seen sqlite might be applicable, but this also seems equally lengthy. I apologise if this question has already been asked, but so far I have failed to find a simple method to resolve it.

here is some example Input and desired output:
#INPUT SOON_S2_L001_R1_001.txt
SOON_S2_L001_R2_001.txt
HELLO_S4_L001_R1_001.txt
HELLO_S4_L001_R2_001.txt
BASH_S1_L001_R1_001.txt
BASH_S1_L001_R2_001.txt
WORLD_S3_L001_R1_001.txt
WORLD_S3_L001_R2_001.txt

#OUTPUT

BASH_S1_L001_R1_001.txt
BASH_S1_L001_R2_001.txt
SOON_S2_L001_R1_001.txt
SOON_S2_L001_R2_001.txt
WORLD_S3_L001_R1_001.txt
WORLD_S3_L001_R2_001.txt
HELLO_S4_L001_R1_001.txt
HELLO_S4_L001_R2_001.txt

Hi I've worked out a solution to this, but I want to know if there is a more direct and simple way of doing it.

What I want to achieve is sorting lines of text by a specific point in the text (the lines of text have no spaces or columns).

My current method for this is to cause a break i.e. make a new column at the same place on every line (just before the point I want to sort by - this being Sn_L001_Rn) and then sort by that column, and then join the two columns back together. this works but it seems overly complicated and clunky. I've seen posts on making a score system with awk, but as mine are going to go to at least 96, then this seems lengthy. also i've seen sqlite might be applicable, but this also seems equally lengthy. I apologise if this question has already been asked, but so far I have failed to find a simple method to resolve it.

here is some example Input and desired output:
#INPUT SOON_S2_L001_R1_001.txt
SOON_S2_L001_R2_001.txt
HELLO_S4_L001_R1_001.txt
HELLO_S4_L001_R2_001.txt
BASH_S1_L001_R1_001.txt
BASH_S1_L001_R2_001.txt
WORLD_S3_L001_R1_001.txt
WORLD_S3_L001_R2_001.txt

#OUTPUT

BASH_S1_L001_R1_001.txt
BASH_S1_L001_R2_001.txt
SOON_S2_L001_R1_001.txt
SOON_S2_L001_R2_001.txt
WORLD_S3_L001_R1_001.txt
WORLD_S3_L001_R2_001.txt
HELLO_S4_L001_R1_001.txt
HELLO_S4_L001_R2_001.txt

to add further complexity, in a situation where the is more than 1 of the same Sn then i would like it to take into account the name (though i think this may be resolvable using flags in sort)

Source Link
Giles
  • 907
  • 7
  • 20

sort text by specific location on each line

Hi I've worked out a solution to this, but I want to know if there is a more direct and simple way of doing it.

What I want to achieve is sorting lines of text by a specific point in the text (the lines of text have no spaces or columns).

My current method for this is to cause a break i.e. make a new column at the same place on every line (just before the point I want to sort by - this being Sn_L001_Rn) and then sort by that column, and then join the two columns back together. this works but it seems overly complicated and clunky. I've seen posts on making a score system with awk, but as mine are going to go to at least 96, then this seems lengthy. also i've seen sqlite might be applicable, but this also seems equally lengthy. I apologise if this question has already been asked, but so far I have failed to find a simple method to resolve it.

here is some example Input and desired output:
#INPUT SOON_S2_L001_R1_001.txt
SOON_S2_L001_R2_001.txt
HELLO_S4_L001_R1_001.txt
HELLO_S4_L001_R2_001.txt
BASH_S1_L001_R1_001.txt
BASH_S1_L001_R2_001.txt
WORLD_S3_L001_R1_001.txt
WORLD_S3_L001_R2_001.txt

#OUTPUT

BASH_S1_L001_R1_001.txt
BASH_S1_L001_R2_001.txt
SOON_S2_L001_R1_001.txt
SOON_S2_L001_R2_001.txt
WORLD_S3_L001_R1_001.txt
WORLD_S3_L001_R2_001.txt
HELLO_S4_L001_R1_001.txt
HELLO_S4_L001_R2_001.txt