The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 03-18-2008
quine quine is offline
Registered User
  
 

Join Date: Mar 2008
Location: Bay Area California
Posts: 68
Hello...

There are a few ways to do this, but if what you want is ALWAYS the digits in the middle of the file name, then this is probably easiest...

First, at the top of your program, put "use File::Basename;" This is a standard module included with Perl... Basename gives you the filename at the end of a path... Suppose the whole path name is in $myfullpath

use File::Basename

$myFile = Basename($myfullpath); # $myFile now RDI00244.rpt

$myFile =~ /(\d)/; #The () around \d (digits) captures the match so...
$mydigits = $1 # $1 because it's the first parentheses set in the patern

or you could do....

$myFile =~ s/(\d)/$1/; # now a direct substitution of the digits into $myFile

Hope that helps
matthew rapaport (quine@sonic.net)