Need help with regex

2003-09-23 Thread Segree, Gareth
> I have a directory of files that I want to move to another directory.
> (eg. ALLY20030111W.eps
>  TEST W20030122
>  HELP WANTED20030901WW.eps
>  GIRL WATCH BIRD 20030101
> etc..)
> 
> I want to be able to parse the filename and replace the date portion with
> any date
> (eg $1="ALLY" $2="20030111" $3="W" $4=".eps")
> Then I want to make $2="20030925" and if $3 is empty then I assign ".eps"
> to $3 or if $4 is empty then assign ".eps"
> 
> 
> How do I do this?
> 
> #!/usr/bin/perl
> # move_file.plx
> use warnings;
> use strict;
> 
> $source = "/path/to/source/";
> $destination = "/path/to/destination/";
> $query = "([A-Za-z]+)(\s*?)([0-9]*)(\s*?)([A-Za-z]*)([eps])"
> opendir DH, $source or die "Couldn't open the current directory: $source";
> while ($_ = readdir(DH)) {
>next if $_ eq "." or $_ eq "..";
> 
>if (/$query/) {
>   print "Copying $_ ...\n";
>   rename $source$_, $destination$_;
>   print "file copied successfully.\n";
>}
> }
> 
> What's wrong with my code. Am I overlooking something?
> 
> 


Need help with regex

2003-09-24 Thread Segree, Gareth
> MAN 2 MAN18800101.eps
The filenames will not have this sort of naming convention.

Files will look like the following.
ALLY20030111W.eps
TEST W20030122
HELP WANTED20030901WW.eps
GIRL WATCH BIRD 20030101
HELPER 20030121.CW.eps


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



NEED HELP WITH REGEX....

2003-07-14 Thread magelord
hi, i have this regex:


\.(?!.png|.log)[^.]*$


how can i replace the .before png and log with nothing? the problem is,
the alternation can be longer, like that:

\.(?!.png|.log|.txt|.c|.cpp and so on )[^.]*$

how could i do that?

THANKS:-)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Need help with regex

2004-07-31 Thread linuxnand
Hello,

I have as the output of an unzip command called from a script the following:

unzip test.zip
Archive:  test.zip
 inflating: arch1.txt
 inflating: arch2.txt
 inflating: arch3.txt
 inflating: arch4.txt
 inflating: arch5.txt
 inflating: arch6.txt

The same I have from a pkware execution :

pkunzip teste.zip
PKZIP(R)  Version 6.0  FAST!  Compression Utility for Linux X86
Copyright 1989-2002 PKWARE Inc.  All Rights Reserved. Evaluation Version
PKZIP Reg. U.S. Pat. and Tm. Off.  Patent No. 5,051,745


Extracting files from .ZIP: teste.zip
   Inflating: arch1.txt
   Inflating: arch2.txt
   Inflating: arch3.txt
   Inflating: arch4.txt
   Inflating: arch5.txt

So, I need some help on how to write a regexp to get the values after inflating, that 
is the filenames, and put them in an array. Both outputs above are stored on a $stdout 
php variable.

Also, I need to be able to indentify errors with the unzip utility that does not 
support some types of zip file, the output is like this:

unzip test1.zip
Archive:  test1.zip
  skipping: test1.txt  `shrink' method not supported

There's a skipping instead of a inflating or Inflating in pkware.

The third situation is an error on the zip file itself :

unzip test2.zip
Archive:  test2.zip
 End-of-central-directory signature not found.  Either this file is not
 a zipfile, or it constitutes one disk of a multi-part archive.  In the
 latter case the central directory and zipfile comment will be found on
 the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of test2.zip or
   test2.zip.zip, and cannot find test2.zip.ZIP, period.

or

pkunzip test2.zip
PKZIP(R)  Version 6.0  FAST!  Compression Utility for Linux X86
Copyright 1989-2002 PKWARE Inc.  All Rights Reserved. Evaluation Version
PKZIP Reg. U.S. Pat. and Tm. Off.  Patent No. 5,051,745

Extracting files from .ZIP: test2.zip
Errors were found in .ZIP file, attempt to fix (es/o)? N

PKZIP: (Z152) No CE signature found

Help is much appreacited.

Thanks in advance. 



__
Switch to Netscape Internet Service.
As low as $9.95 a month -- Sign up today at http://isp.netscape.com/register

Netscape. Just the Net You Need.

New! Netscape Toolbar for Internet Explorer
Search from anywhere on the Web and block those annoying pop-ups.
Download now at http://channels.netscape.com/ns/search/install.jsp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Need help with regex

2004-11-04 Thread Kevin Old
Hello everyone,

I have a line like the following:

my $line = "31232000 07/28/04 DUC000 NET 60 DAYS  RD64
   UPSGNDSVR   PREPAID";

What I'm looking for in lines like this are the customer number
(DUC000) and a "code" that starts with UPS, or if the code doesn't
start with UPS idealy I'd like to have whatever was in that place
returned, but I can't figure that out and can settle for just nothing
returned along with the customer number.

The problem with the regex below is that if the shipping "code"
doesn't start with UPS, it doesn't return the custnum.

$_ =~ /\d+\s+\d+\/\d+\/\d+\s+(\w+).*(UPS\w+)\s/;
$custnum = $1;
$isups = $2;

I know I'm missing something basic.  I've even tried grouping it and
trying the zero or more matching:

$_ =~ /\d+\s+\d+\/\d+\/\d+\s+(\w+).*(?:(UPS\w+)\s)*/

This doesn't match anything.

Any ideas?  

Thanks,
-- 
Kevin Old
[EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Need help with regex

2003-09-24 Thread Rob Dixon
Gareth Segree wrote:
>
> I have a directory of files that I want to move to another directory.
> (eg. ALLY20030111W.eps
>  TEST W20030122
>  HELP WANTED20030901WW.eps
>  GIRL WATCH BIRD 20030101
> etc..)
>
> I want to be able to parse the filename and replace the date portion with
> any date
> (eg $1="ALLY" $2="20030111" $3="W" $4=".eps")
> Then I want to make $2="20030925" and if $3 is empty then I assign ".eps"
> to $3 or if $4 is empty then assign ".eps"
>
>
> How do I do this?
>
> #!/usr/bin/perl
> # move_file.plx
> use warnings;
> use strict;
>
> $source = "/path/to/source/";
> $destination = "/path/to/destination/";
> $query = "([A-Za-z]+)(\s*?)([0-9]*)(\s*?)([A-Za-z]*)([eps])"
> opendir DH, $source or die "Couldn't open the current directory: $source";
> while ($_ = readdir(DH)) {
>next if $_ eq "." or $_ eq "..";
>
>if (/$query/) {
>   print "Copying $_ ...\n";
>   rename $source$_, $destination$_;
>   print "file copied successfully.\n";
>}
> }
>
> What's wrong with my code. Am I overlooking something?

Your code doesn't attempt to make the replacement that you describe: it
simply copies a file from one directory to another with no change of
name. More precisely it would, if it were valid Perl. Have you put in

  use warnings;
  use strict;

for the purposes of your post? Because your program will have thrown
up several errors that you should be able to correct.

With regard to editing the file name, you need to say more about
what source filenames are possible. If the only numeric content of
the name is the date field then it's very easy, but if you could
have

  MAN 2 MAN18800101.eps

then it's a little tricker.

Let us know,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Need help with regex

2004-07-31 Thread Gunnar Hjalmarsson
[EMAIL PROTECTED] wrote:
So, I need some help on how to write a regexp to get the values 
after inflating, that is the filenames, and put them in an array. 
Both outputs above are stored on a $stdout php variable.
Well, this list is for discussing Perl, not PHP. If you want a regexp
in PHP, you'd better study the applicable PHP docs.
If you want to switch to Perl, "perldoc perlrequick" is an appropriate
place to start. Give it a try yourself with help of the docs, and
come back here if you can't figure it out.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Need help with regex

2004-11-04 Thread Larsen, Errin M HMMA/IT
> -Original Message-
> From: Kevin Old [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, November 04, 2004 9:38 AM
> To: [EMAIL PROTECTED]
> Subject: Need help with regex
> 
> 
> Hello everyone,
> 

  Hi!


> I have a line like the following:
> 
> my $line = "31232000 07/28/04 DUC000 NET 60 DAYS  RD64
>UPSGNDSVR   PREPAID";
> 
> What I'm looking for in lines like this are the customer number
> (DUC000) and a "code" that starts with UPS, or if the code 
> doesn't start with UPS idealy I'd like to have whatever was 
> in that place returned, 

  <>

  Does the information in your "line" above always have the same
information in the same fields?

  For example, is the Customer number always the 3rd string of
information in your line?

  If so, then you can grab your stuff without matching with a nice
split!

my( $customer, $code ) = ( split ' ', $line )[2, 8];


  I hope that helps,

  --Errin

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Need help with regex

2004-11-04 Thread Kevin Old
On Thu, 4 Nov 2004 10:05:08 -0600, Larsen, Errin M HMMA/IT
<[EMAIL PROTECTED]> wrote:
> > -Original Message-
> > From: Kevin Old [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, November 04, 2004 9:38 AM
> > To: [EMAIL PROTECTED]
> > Subject: Need help with regex
>   <>
> 
>   Does the information in your "line" above always have the same
> information in the same fields?

No, unfortunately it doesn't, but thanks for the suggestion.
Kevin
-- 
Kevin Old
[EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Need help with regex

2004-11-04 Thread Robert Citek
On Thursday, Nov 4, 2004, at 09:38 US/Central, Kevin Old wrote:
my $line = "31232000 07/28/04 DUC000 NET 60 DAYS  RD64
   UPSGNDSVR   PREPAID";
What I'm looking for in lines like this are the customer number
(DUC000) and a "code" that starts with UPS, or if the code doesn't
start with UPS idealy I'd like to have whatever was in that place
returned, but I can't figure that out and can settle for just nothing
returned along with the customer number.
Can you tell us a little more about the data?  Are the fields fixed 
with?  Is the "code" that starts with UPS always the second to last 
word?  Here's a possible solution based on guessing the formatting of 
the input data:

$ perl -e 'my $line = "31232000 07/28/04 DUC000 NET 60 DAYS  " .
  "RD64   UPSGNDSVR   PREPAID";
  $line =~ /\d+\s+\d+\/\d+\/\d+\s+(\w+).*\s+(\w+)\s+\S+$/;
  print "$1, $2\n"; '
DUC000, UPSGNDSVR
Here's another version which "simplifies" the pattern matches into 
spaces and non-spaces:

$ perl -e 'my $line = "31232000 07/28/04 DUC000 NET 60 DAYS  " .
  "RD64   UPSGNDSVR   PREPAID";
  $line =~ /^\S+\s+\S+\s+(\S+).*\s+(\S+)\s+\S+$/;
  print "$1, $2\n"; '
DUC000, UPSGNDSVR
But if that works, you may want to revisit using split.
Let us know what you try and what works.
Regards,
- Robert
http://www.cwelug.org/downloads
Help others get OpenSource.  Distribute FLOSS for
Windows, Linux, *BSD, and MacOS X with BitTorrent
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Need help with regex

2004-11-04 Thread Scott Pham
Why don't you just split the line and use the whitespace as separator?

$line =~ s/\s+/ /;
my ($record,$date,$cust,$temp1,$temp2,$temp3,$temp4,$temp5,$shipping,$paid)
= split (/ /,$line);



-Original Message-
From: Kevin Old [mailto:[EMAIL PROTECTED] 
Sent: Thursday, November 04, 2004 10:38 AM
To: [EMAIL PROTECTED]
Subject: Need help with regex

Hello everyone,

I have a line like the following:

my $line = "31232000 07/28/04 DUC000 NET 60 DAYS  RD64
   UPSGNDSVR   PREPAID";

What I'm looking for in lines like this are the customer number
(DUC000) and a "code" that starts with UPS, or if the code doesn't
start with UPS idealy I'd like to have whatever was in that place
returned, but I can't figure that out and can settle for just nothing
returned along with the customer number.

The problem with the regex below is that if the shipping "code"
doesn't start with UPS, it doesn't return the custnum.

$_ =~ /\d+\s+\d+\/\d+\/\d+\s+(\w+).*(UPS\w+)\s/;
$custnum = $1;
$isups = $2;

I know I'm missing something basic.  I've even tried grouping it and
trying the zero or more matching:

$_ =~ /\d+\s+\d+\/\d+\/\d+\s+(\w+).*(?:(UPS\w+)\s)*/

This doesn't match anything.

Any ideas?  

Thanks,
-- 
Kevin Old
[EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Need help with regex

2004-11-04 Thread Robert Citek
On Thursday, Nov 4, 2004, at 10:49 US/Central, Scott Pham wrote:
Why don't you just split the line and use the whitespace as separator?
$line =~ s/\s+/ /;
my  
($record,$date,$cust,$temp1,$temp2,$temp3,$temp4,$temp5,$shipping,$paid 
)
= split (/ /,$line);
As I was reminded the other day, split works with an RE, so you can  
skip that first list :

$ perl -e 'my $line = "31232000 07/28/04 DUC000 NET 60 DAYS  " .
  "RD64   UPSGNDSVR   PREPAID";
  my ($cust,$shipping) = (split (/\s+/,$line))[2,-2];
  print "$cust, $shipping\n";'
DUC000, UPSGNDSVR
But all that depends on the formatting of the input lines.
Regards,
- Robert
http://www.cwelug.org/downloads
Help others get OpenSource.  Distribute FLOSS for
Windows, Linux, *BSD, and MacOS X with BitTorrent
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Need help with regex

2004-11-04 Thread Kevin Old
On Thu, 4 Nov 2004 10:58:16 -0600, Robert Citek
<[EMAIL PROTECTED]> wrote:
> 
> On Thursday, Nov 4, 2004, at 10:49 US/Central, Scott Pham wrote:
> > Why don't you just split the line and use the whitespace as separator?
> >
> > $line =~ s/\s+/ /;
> > my
> > ($record,$date,$cust,$temp1,$temp2,$temp3,$temp4,$temp5,$shipping,$paid
> > )
> > = split (/ /,$line);
> 
> As I was reminded the other day, split works with an RE, so you can
> skip that first list :
> 
> $ perl -e 'my $line = "31232000 07/28/04 DUC000 NET 60 DAYS  " .
>"RD64   UPSGNDSVR   PREPAID";
>my ($cust,$shipping) = (split (/\s+/,$line))[2,-2];
>print "$cust, $shipping\n";'
> DUC000, UPSGNDSVR
> 
> But all that depends on the formatting of the input lines.

Thanks for the replies.  My first thought was to use split on the
spaces, but the "NET 60 DAYS" could throw that off and the fact that
the line can have additional spaces, etc.

I found out that the line I am trying to parse is being produced in
fixed-width, so here's my solution:

my @line = unpack("A8 x1 A8 x1 A6 x1 A16 x1 A5 x1 A13 x1 A11 x1 A9", $_);
$custnum = $line[2];
$isups = $line[6];

Thanks!
-- 
Kevin Old
[EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Need help with regex

2004-11-04 Thread John W. Krahn
Kevin Old wrote:
Hello everyone,
Hello,
I have a line like the following:
my $line = "31232000 07/28/04 DUC000 NET 60 DAYS  RD64
   UPSGNDSVR   PREPAID";

What I'm looking for in lines like this are the customer number
(DUC000) and a "code" that starts with UPS, or if the code doesn't
start with UPS idealy I'd like to have whatever was in that place
returned, but I can't figure that out and can settle for just nothing
returned along with the customer number.
The problem with the regex below is that if the shipping "code"
doesn't start with UPS, it doesn't return the custnum.
$_ =~ /\d+\s+\d+\/\d+\/\d+\s+(\w+).*(UPS\w+)\s/;
$custnum = $1;
$isups = $2;
I know I'm missing something basic.  I've even tried grouping it and
trying the zero or more matching:
$_ =~ /\d+\s+\d+\/\d+\/\d+\s+(\w+).*(?:(UPS\w+)\s)*/
This doesn't match anything.
It looks like you have fixed length fields so you may want to use unpack.
my ( $custnum, $isups ) = unpack 'x18 A7 x37 A12', $line;

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]