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
$ perl -le'
my @x = qw(
324yellow
34house
black
54532
15m21red56
44dfdsf8sfd23
);
print "only the numbers at the beginning before some alpha text:";
for ( @x ) {
print $1 if /^(\d+)(?=\D)/;
}
print "only the numbers within the alpha text:";
for ( @x ) {
print $1 if /(?<=\D)(\d+)(?=\D)/;
}
print "only the numbers at the end after some alpha text:";
for ( @x ) {
print $1 if /(?<=\D)(\d+)$/;
}
'
only the numbers at the beginning before some alpha text:
324
34
15
44
only the numbers within the alpha text:
21
8
only the numbers at the end after some alpha text:
56
23
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/