hi all,
was wanting to know how to search for decimal numbers in a file ? am using solaris 8 and have tried a few options with "grep" but none of them seem to work.
thanks in advance.
hi all,
was wanting to know how to search for decimal numbers in a file ? am using solaris 8 and have tried a few options with "grep" but none of them seem to work.
thanks in advance.
Here's a Perl script that will print almost all decimal numbers found in a file.
#!/usr/bin/perl
# You may need to change this path to /usr/local/bin/perl
open (FILE,"input.txt");
@lines = <FILE>;
close (FILE);
foreach $l (@lines) {
if ($l =~ /\d+\.\d+/) {
$l =~ s/.*\D(\d+\.\d+)\D.*/$1/;
print $l;
}
}
exit;
I say almost all because this version will find a max of 1 decimal number per line. A bit more coding and it can find multiples.