Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with character sort

Status
Not open for further replies.

grazinggoat

Programmer
Mar 12, 2008
41
0
0
US
I have 30 various channele split into groups

serv1g1s1
dbserv100g5s1
serv1g4s2
dbserv20g15s6

I want to be able to break the list down by the groups (ie g1s1, g4s2, g5s1, g15s6 )
how can i sort when there can be any number of characters before the g, inbetween the s?

I only want the list to chop down to show just the groups

g1s1
g4s2
g15s6

I have no idea on how to do this? I looked up sort an am not sure what could be done using sed or awk Any thoughts please?
 
Hi

Off-topic solution, but my time is limited now. If only the "g*s*" parts are needed, I would do this way :
Code:
grep -o 'g[0-9]\+s[0-9]\+$' /input/file | sort -k 1.2n


Feherke.
feherke.ga
 
You could use grep, sed, or awk to achieve this...

Sed:
Code:
sed 's/.*\(g.*\)$/\1/g' gg.data | sort -V
Awk:
Code:
awk 'match($0,/g.*$/) {print substr($0,RSTART,RLENGTH)}' gg.data | sort -V
output:
g1s1
g4s2
g5s1
g15s6

thread80-1459823
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top