04-28-07 12:18 PM
ruds <rudranee@gmail.com> wrote:
> I have a string such that it starts with a number and has words in
> double qoutes appended to it like: 1234"ancb_adsds"
> I want to know how can i extract only the number from the whole
> string??
> I not very good at regular exressions, but i tried comparing with
> [0-9] in if block...but did'nt get any success.
Sorry, but you must tell in which language you want to do that.
Since you mention regular expressions it's probably not for a
shell script since normal shells don't do regular expressions.
Should it be for a shell like bash anyway you could use e.g.
a='1234ancb_adsds"'
b=${a%%\"*}
echo $b
Or you could invoke sed (again with bash syntax):
a='1234ancb_adsds"'
b=`echo $a | sed 's/^\([0-9]*\).*$/\1/'`
echo $b
Mind the backticks around the echo and sed command, they are
required to catch the output of the command.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
[ Post a follow-up to this message ]
|