Navigation: Main Page » Computer / Recreational / Science / Society / Television
 
Web N-N-A.com
         
Computer Groups Forum Index  »  Editors  »  Geting only the numbers out...
Page 1 of 1    
Author Message
SamG
Posted: Thu Mar 29, 2007 8:02 am
Guest
I need sed onliner, where is have 243xx as string in file[Thats the
only line in the file and xx could be anythin 'ab' 'a1' but cannot be
'1a'.] and i want only 243 to be return.

Could this be done using either sed or awk.
RalfB
Posted: Thu Mar 29, 2007 8:02 am
Guest
On 29 Mrz., 06:38, "SamG" <mad.vi...@gmail.com> wrote:
Quote:
I need sed onliner, where is have 243xx as string in file[Thats the
only line in the file and xx could be anythin 'ab' 'a1' but cannot be
'1a'.] and i want only 243 to be return.

Could this be done using either sed or awk.


sed 's/\([0-9]*\).*/\1/'

hth

Ralf
SamG
Posted: Thu Mar 29, 2007 4:04 pm
Guest
RalfB wrote:
Quote:
On 29 Mrz., 06:38, "SamG" <mad.vi...@gmail.com> wrote:
I need sed onliner, where is have 243xx as string in file[Thats the
only line in the file and xx could be anythin 'ab' 'a1' but cannot be
'1a'.] and i want only 243 to be return.

Could this be done using either sed or awk.


sed 's/\([0-9]*\).*/\1/'

hth

Ralf

Thanks Ralf,

I have a long way to go in sed. it looks so simple though!
sjdevnull@yahoo.com
Posted: Thu Mar 29, 2007 4:04 pm
Guest
SamG wrote:
Quote:
RalfB wrote:
On 29 Mrz., 06:38, "SamG" <mad.vi...@gmail.com> wrote:
I need sed onliner, where is have 243xx as string in file[Thats the
only line in the file and xx could be anythin 'ab' 'a1' but cannot be
'1a'.] and i want only 243 to be return.

Could this be done using either sed or awk.


sed 's/\([0-9]*\).*/\1/'

hth

Ralf

Thanks Ralf,

I have a long way to go in sed. it looks so simple though!

You'll be well-served by learning regular expressions; they're used in
sed, vi, perl, python, grep, Java, ruby, etc. The details differ in
different implementations, but most of the core ideas (including,
e.g., the [0-9] stuff) are the same everywhere, so you needn't feel
like you're putting a lot of time into learning _just_ sed.

Just keep in mind that they aren't general-purpose parsers, and thus
aren't applicable to all problems. They're great for certain tasks,
and incredibly powerful for one-off search or replace operations and
for dealing with some kinds of texts. But there is a kernel of truth
in Jamie Zawinksi's (author of XEmacs and the Unix version of
Netscape, among other things) famous observation, "Some people have a
problem and think, "I'll use a regular expression." Now they have 2
problems!" If you're trying to shoehorn them into, say, matching
nested parenthesis or other moderately complex operations you need to
think about a parser.

Still, when they apply they're powerful and fast. And they apply
surprisingly often.
 
Page 1 of 1       All times are GMT
The time now is Wed Jan 07, 2009 5:07 am