Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Patterns

Status
Not open for further replies.

rudorathod

IS-IT--Management
Jun 4, 2007
11
0
0
US
I have files coming to the server which are as follows

<<TYPE>>_<<DATE_SENT>>_01-<<DATE_DOWNLOADED>>.txt.gpg

so for example i get two files

TRANSPORT_20071020_01-20071023.txt.gpg and
CALCULATE_20071020_01-20071023.txt.gpg

based on the type i want to move those files to different locations

so if TRANSPORT_20071024_01.txt.gpg it goes to directory

transport/YYYYMM/TRANSPORT_20071024_01.txt.gpg

and if CALCULATE_20071024_01.txt.gpg it goes to directory

calculate/YYYYMM/CALCULATE_20071024_01.txt.gpg


i have the following code but it goes to same location, how can i change it to make the way i want

'/(\w+)_(\d{4})(\d{2})(\d{2})_(\d{2})-\d*\.TXT\.pgp'
=> 'transport/$2$3/$1-$2$3$4_$5.txt.pgp',

 
Since you have not stated if there are any other patterns, I'm assuming these are only ones you have.

if ($fileName =~ /^TRANSPORT/) {
`mv $fileName \$path`; <-Unix Env
rename xx/xx xx/xx; <- perl Option.
} elsif ($fileName =~ /^CALCULATE/) {
`mv $fileName \$path`; <-Unix Env
rename xx/xx xx/xx; <- perl Option.
} else {
print "No files found with the matching pattern\n";
}
 
You say: txt.gpg
in your regexp you have: \.TXT\.pgp

they do not match



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
the TXT/txt still do not match. If you want a case-insensitive match use the "i" option with your regexp:

Code:
/(\w+)_(\d{4})(\d{2})(\d{2})_(\d{2})-\d*\.TXT\.gpg/[red]i[/red]

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top