Afficher un message
Vieux 08/11/2006, 12h23   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: finding position of 1st occurence of a [0-9] char in a string

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
  Réponse avec citation
 
Page generated in 0,05464 seconds with 9 queries