Re: show only numbers before, within or after the text
- From: jwkrahn@xxxxxxx (John W. Krahn)
- Date: Sat, 28 Jun 2008 22:50:40 -0700
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
.
- References:
- show only numbers before, within or after the text
- From: Luca Villa
- show only numbers before, within or after the text
- Prev by Date: Re: Using System to read mixed cased environment variables on Windows
- Next by Date: MIME::QuotedPrint - extra '=' and linebreak?
- Previous by thread: Re: show only numbers before, within or after the text
- Next by thread: Re: show only numbers before, within or after the text
- Index(es):
Relevant Pages
|