|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
A string [a-zA-Z]*[0-9]* eg "Some_Name_1.85.1.35". The end result I
want is to obtain only the non numeric characters from the start of the string up until the 1st occurence of a numeric character ("Some_Name_" using the example). But how best to do this? If I can get the position of the first numeric character I can do expr substr. Though there may be a better and more complete solution with the likes of awk, but I'm still learning awk. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
2006-11-8, 03:01(-08), Dundonald:
> A string [a-zA-Z]*[0-9]* eg "Some_Name_1.85.1.35". The end result I > want is to obtain only the non numeric characters from the start of the > string up until the 1st occurence of a numeric character ("Some_Name_" > using the example). But how best to do this? If I can get the > position of the first numeric character I can do expr substr. Though > there may be a better and more complete solution with the likes of awk, > but I'm still learning awk. Assuming a Unix sh conformant shell: string="Some_Name_1.85.1.35" newstring=${string%%[0-9]*} With any shell: expr "x$string" : 'x\([^0-9]*\)' "expr substr" is not standard. -- Stéphane |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Stephane CHAZELAS wrote: > 2006-11-8, 03:01(-08), Dundonald: > > A string [a-zA-Z]*[0-9]* eg "Some_Name_1.85.1.35". The end result I > > want is to obtain only the non numeric characters from the start of the > > string up until the 1st occurence of a numeric character ("Some_Name_" > > using the example). But how best to do this? If I can get the > > position of the first numeric character I can do expr substr. Though > > there may be a better and more complete solution with the likes of awk, > > but I'm still learning awk. > > Assuming a Unix sh conformant shell: > > string="Some_Name_1.85.1.35" > newstring=${string%%[0-9]*} Thanks Stephane. Is it possible for you to explain how the above works or pointing me in the right direction (rather than me blindly using it and not learning anything)? Ta. > > With any shell: > > expr "x$string" : 'x\([^0-9]*\)' > > "expr substr" is not standard. > > -- > Stéphane |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
2006-11-8, 05:54(-08), Dundonald:
> > Stephane CHAZELAS wrote: >> 2006-11-8, 03:01(-08), Dundonald: >> > A string [a-zA-Z]*[0-9]* eg "Some_Name_1.85.1.35". The end result I >> > want is to obtain only the non numeric characters from the start of the >> > string up until the 1st occurence of a numeric character ("Some_Name_" >> > using the example). But how best to do this? If I can get the >> > position of the first numeric character I can do expr substr. Though >> > there may be a better and more complete solution with the likes of awk, >> > but I'm still learning awk. >> >> Assuming a Unix sh conformant shell: >> >> string="Some_Name_1.85.1.35" >> newstring=${string%%[0-9]*} > > Thanks Stephane. Is it possible for you to explain how the above works > or pointing me in the right direction (rather than me blindly using it > and not learning anything)? Ta. [...] See the details about ${var%%word} in your shell manual or at http://www.opengroup.org/onlinepubs/...l#tag_02_06_02 -- Stéphane |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Stephane CHAZELAS wrote: > 2006-11-8, 05:54(-08), Dundonald: > > > > Stephane CHAZELAS wrote: > >> 2006-11-8, 03:01(-08), Dundonald: > >> > A string [a-zA-Z]*[0-9]* eg "Some_Name_1.85.1.35". The end result I > >> > want is to obtain only the non numeric characters from the start of the > >> > string up until the 1st occurence of a numeric character ("Some_Name_" > >> > using the example). But how best to do this? If I can get the > >> > position of the first numeric character I can do expr substr. Though > >> > there may be a better and more complete solution with the likes of awk, > >> > but I'm still learning awk. > >> > >> Assuming a Unix sh conformant shell: > >> > >> string="Some_Name_1.85.1.35" > >> newstring=${string%%[0-9]*} > > > > Thanks Stephane. Is it possible for you to explain how the above works > > or pointing me in the right direction (rather than me blindly using it > > and not learning anything)? Ta. > [...] > > See the details about ${var%%word} in your shell manual or at > http://www.opengroup.org/onlinepubs/...l#tag_02_06_02 Excellent resource, thanks. |
|
![]() |
| Outils de la discussion | |
|
|