logo       

Re: How to extract Numbers: msg#00069

editors.sed.user

Subject: Re: How to extract Numbers


On Tue, 20 Dec 2005 12:40:45 +0800, Surya Kiran Gullapalli wrote:

>
> Hi all,
> I've a string like this
>
> AAAxx.yy
> where AAA are letters and xx and yy are numbers. I want to extract xx.yy
> from the string. I'm doing some thing like this.
>
> echo abc12.34 | sed -e 's|^\D*\(\d.*\)|\1|g'
>
> but the result i'm getting is abc12.34 only. Where am i doing wrong ?
>

\D and \d metacharacters are not supported by most seds. However, "ssed"
does support them when -R option present.

ssed -R 's|^\D*\(\d.*\)|\1|g'

Use [0-9] and [^0-9] when you are using other seds instead.
But in your example, you can just delete the leading letters by command:

sed 's/[a-zA-Z]//g'
or:
sed 's/[^0-9]*//'

--
Regards,
hq00e



------------------------ Yahoo! Groups Sponsor --------------------~-->
Most low income homes are not online. Make a difference this holiday season!
http://us.click.yahoo.com/5UeCyC/BWHMAA/TtwFAA/dkFolB/TM
--------------------------------------------------------------------~->

--

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/

<*> To unsubscribe from this group, send an email to:
sed-users-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/






<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise