Re: show only numbers before, within or after the text
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Sun, 29 Jun 2008 20:03:43 +0100
sisyphus wrote:
On Jun 29, 1:18 am, lucavi...@xxxxxxxxxxxx (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
Just for fun - ie ignoring prettiness and requirements 2) and 3):
my @stuff = qw(324yellow 34house black 54532 15m21red56
44dfdsf8sfd23);
for(@stuff) {
$x = $_ * 1;
if($x == 0 && substr($_, 0, 1) ne "0") {$x = undef}
if($x eq $_) {$x = undef}
print $x, "\n" if defined $x;
}
Or, rather
for (@stuff) {
no warnings 'numeric';
my $x = $_+0;
print "$x\n" unless $x eq $_ or $x == 0 and /^[^0]/;
}
Rob
.
- References:
- show only numbers before, within or after the text
- From: Luca Villa
- Re: show only numbers before, within or after the text
- From: Sisyphus
- show only numbers before, within or after the text
- Prev by Date: Re: show only numbers before, within or after the text
- Next by Date: Re: 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
|