Re: show only numbers before, within or after the text



Luca Villa wrote:
I have a long text file like this:

324yellow
34house
black
54532
15m21red56
44dfdsf8sfd23

How can I obtain (Perl - Windows/commandline/singleline) the
following?

1) only the numbers at the beginning before some alpha text, like
this:

324
34
15
44

2) only the numbers within the alpha text, like this:

21
8

3) only the numbers at the end after some alpha text, like this:

56
23

You should learn about regular expressions.

perldoc perlrequick
perldoc perlretut
perldoc perlre

The m// operator is documented in

perldoc perlop

As regards one-liners at command line:

perldoc perlrun

This is a solution to the first of your examples:

perl -ne "print qq($&\n) if /^\d+(?=[[:alpha:]])/" file.txt

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages

  • Re: show only numbers before, within or after the text
    ... sisyphus wrote: ... How can I obtain (Perl - Windows/commandline/singleline) the ... only the numbers at the beginning before some alpha text, ...
    (perl.beginners)
  • Re: show only numbers before, within or after the text
    ... sisyphus wrote: ... How can I obtain (Perl - Windows/commandline/singleline) the ... only the numbers at the beginning before some alpha text, ...
    (perl.beginners)
  • Re: show only numbers before, within or after the text
    ... How can I obtain (Perl - Windows/commandline/singleline) the ... only the numbers at the beginning before some alpha text, ... if{$x = undef} ...
    (perl.beginners)
  • Re: Help on regular expression !!
    ... refer any good reference for Regular expression for a beginer like me, ... Have you read the documentation that comes with Perl? ... I will give it a shot the documentation you have referred. ...
    (perl.beginners)
  • Re: Very easy question
    ... This is a private course (one of those learn in ... Recently i found out iv wasted my money and as you can imagine, ... and you can also signed up for the new perl college which is FREE! ... Just about to look at perldoc perlrequick and perlretut, ...
    (perl.beginners)