Re: reg exp using \G

2005-08-03 Thread DBSMITH
   
 Jay Savage
 [EMAIL PROTECTED] 
 l.com To 
   [EMAIL PROTECTED]
 08/02/2005 05:43  [EMAIL PROTECTED], beginners 
 PMperl beginners@perl.org   
cc 
   
 Please respond to Subject 
Jay Savage Re: reg exp using \G
 [EMAIL PROTECTED] 
  l.com   
   
   
   
   







Please don't top post. I think you've been asked this before.


On 8/2/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 ok I understand now...thanks, but I tried it and it is still stopping at
 original1.1
 I then modified it to print YE if ($1) but never saw YE in
STDOUT.


Tha's because as a one liner it doesn't use parentheses. And also
becuase YES isn't a string, it's a constant. Do you have warnings
turned on? warnings and strict would catch these sorts of things.

print Yes if $1;   # or
if ($1) {print Yes}

Your choice.


  #!/usr/bin/perl
  use strict;
  use warnings;
 
  while (DATA) {
  if (/AA/ ... /(CC)/) {
  print;
  if ($1) {
  while (DATA) {
  # this regex defines when your section is done
  last if /^\s*$/;
  print;
  }

 # so you don't have to spin over the rest of the file
 last;

  }
  }
  }

I think we need a clearer description of what you want to do here. At
least I do. will your last line have original.1? Or will it have
something else? i don't think anyone knows what the end of
original.1 means. original.1 is a string, and the current code
matches that string. If you need to match the end of the string, use
'/original\.1$/'.

I think, though that you mean the end of some block of lines in your data
file.

It looks to me like you want something along the lines of :

  while() {
if (/allsets/ .. /original\.1/) {
  print;
} elsif (/media/ .. /Total/) {
  print;
}
  }

-- j
--



BOTTOM POST

I got it working and the code I am using is now

open (ARC, archiver -lv |) or die $!;
my $flag=0;
foreach (ARC)
{
if (/(?i)allsets/)
{
$flag=1;
}
if ($flag==1)
{
print $_;
  }
}

as opposed to

if (/allsets/ .. /original1.1/ )

because I needed the data after original1.1.

thank you
derek






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




Re: reg exp using \G

2005-08-02 Thread Dave Gray
On 8/2/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 I think I am on the right track as far as what assertion to use.  I need to
 print from one string to another using .. with \G

Why do you want to use \G?

 My goal is to capture from allsets down.
 Here is my code:
 
 #!/usr/bin/perl
 use strict;
 use warnings;
 $ENV{PATH} = qq(/opt/SUNWsamfs/sbin:/usr/bin);
 open (ARC, archiver -lv |) or die $!;
 
 foreach (ARC)
 {
 ##-- Tape --##
 if (/allsets/ .. /fs_clinical.1/)

You need to escape dots in regular expressions '\.'

 {
 print $_;
 my $tape =$1;

Your regex isn't capturing anything, so $1 will always be undefined.

 } else {
   /  \G 'heartlab.1'/

What are you trying to do here? You need to escape dots in regular
expressions '\.'

   }
 }
 close (ARC);

I think you would benefit greatly from trying to generalize your
problem and writing a simple test script that simulates the problem
you're trying to solve. Then if you're still stuck, post that test
script here, as opposed to that 5 billion line data file which is
mostly irrelevant anyway.

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




Re: reg exp using \G

2005-08-02 Thread DBSMITH
Dave,

technically you are correct about escaping the dot, but in this particular
situation my regexp is working.  I will escape the dot.
my goal again is to print from one sting to another from allsets
down.  I apologize for the long output if data, but I want to reflect 100%
accuracy.

Any ideas on a simple for loop with a regexp?

thanks




   
 Dave Gray 
 [EMAIL PROTECTED] 
 omTo 
   beginners@perl.org  
 08/02/2005 02:19   cc 
 PM
   Subject 
   Re: reg exp using \G
 Please respond to 
 Dave Gray 
 [EMAIL PROTECTED] 
om
   
   




On 8/2/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 I think I am on the right track as far as what assertion to use.  I need
to
 print from one string to another using .. with \G

Why do you want to use \G?

 My goal is to capture from allsets down.
 Here is my code:

 #!/usr/bin/perl
 use strict;
 use warnings;
 $ENV{PATH} = qq(/opt/SUNWsamfs/sbin:/usr/bin);
 open (ARC, archiver -lv |) or die $!;

 foreach (ARC)
 {
 ##-- Tape --##
 if (/allsets/ .. /fs_clinical.1/)

You need to escape dots in regular expressions '\.'

 {
 print $_;
 my $tape =$1;

Your regex isn't capturing anything, so $1 will always be undefined.

 } else {
   /  \G 'heartlab.1'/

What are you trying to do here? You need to escape dots in regular
expressions '\.'

   }
 }
 close (ARC);

I think you would benefit greatly from trying to generalize your
problem and writing a simple test script that simulates the problem
you're trying to solve. Then if you're still stuck, post that test
script here, as opposed to that 5 billion line data file which is
mostly irrelevant anyway.

--
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: reg exp using \G

2005-08-02 Thread John Doe
[EMAIL PROTECTED] am Dienstag, 2. August 2005 19.36:
 reg exp using \G
  Datum: 2.8.05  19:36:44
  Von: [EMAIL PROTECTED]
  An: beginners@perl.org

 All,

 I think I am on the right track as far as what assertion to use.  I need to
 print from one string to another using .. with \G

Your boss the reason that you *need* to? ;-)

 My goal is to capture from allsets down.

 thank you



 Here is my code:

 #!/usr/bin/perl
 use strict;
 use warnings;
 $ENV{PATH} = qq(/opt/SUNWsamfs/sbin:/usr/bin);

Nice to see :-)

 open (ARC, archiver -lv |) or die $!;

         foreach (ARC)
         {
                 ##-- Tape --##
                 if (/allsets/ .. /fs_clinical.1/)

You are in your foreach loop. $_ contains *one* line. I've the impression that 
here you somehow want to treat multiple lines with your if condition.

BTW, the . in your regex stands for any char, not for a literal ..

                 {
                         print $_;
                         my $tape =$1;

You didn't capture in a regex, so $1 contains nothing.

                 } else {
       /  \G 'heartlab.1'/

\G is not usable here: It refers to the last match of the *same* string.  But 
a last match doesn't occur  in the program flow: Per line in the foreach 
loop, you visit either the if or the else part.

       }
         }
 close (ARC);

add a or die or at least or warn here.


 __END_CODE__
 __BEGIN_DATA__

Your problem, if I understand it, is to extract some adjacent lines, the first 
line and the last line containing a keyword.

One approach (and not the best/shortest I suppose) could be:
- read in lines until the start line is found
- accumulate additional lines until end line is found.

[...snipped most of the big data]

 Archive sets:
 allsets


 back.1
  media: sf
  Volumes:
    STK000
  Total space available:   60.8G

 back.2
  media: sf
  Volumes:
    STK005
  Total space available:   60.9G

 clinical1.1
  media: sf
  Volumes:
    STK000
  Total space available:   60.8G

 darch.1
  media: sf
  Volumes:
    STK000
  Total space available:   60.8G

 fs_clinical.1
  Destination: disk1 (/darchive/data1)
[...]

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




Re: reg exp using \G

2005-08-02 Thread Dave Gray
On 8/2/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 technically you are correct about escaping the dot, but in this particular
 situation my regexp is working.  I will escape the dot.
 my goal again is to print from one sting to another from allsets
 down.  I apologize for the long output if data, but I want to reflect 100%
 accuracy.
 
 Any ideas on a simple for loop with a regexp?

for (ARC) {
  print if /one string/ .. /another/;
}

You already had that solution, though. What am I missing?

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




Re: reg exp using \G

2005-08-02 Thread DBSMITH
yes but the problem is my start point and end point have identical entries
under them.  It is stopping at original1.1 when I need for it to stop at
the end of original1.1 and print

media: sf
 Volumes:
   STK000
 Total space available:   60.8G

as opposed to just allsets to original1.1

For example,  stops at original1.1


for (ARC) {
  print if /allsets/ .. /original1\.1/;
}


and in the data file:

Archive sets:
allsets


back.1
 media: sf
 Volumes:
   STK000
 Total space available:   60.8G

back.2
 media: sf
 Volumes:
   STK005
 Total space available:   60.9G

clinical1.1
 media: sf
 Volumes:
   STK000
 Total space available:   60.8G

darch.1
 media: sf
 Volumes:
   STK000
 Total space available:   60.8G

fs_clinical.1
 Destination: disk1 (/darchive/data1)

fs_clinical.2
 sort:path
 media: sg
 Volumes:
   F01133
   F01134
   F01135
   F01136
   F01137
   F01138
   F01139
   F01140
 Total space available:  151.6G

fs_clinical.3
 sort:path
 media: sf
 Volumes:
   F02029
   F02030
   F02031
   F02032
   F02033
   F02034
   F02035
   F02036
   F02012
 Total space available:  796.1G

fs_heartlab.1
 sort:path
 media: sg
 Volumes:
   H01134
   H01135
   H01136
   H01137
   H01138
   H01139
   H01140
   H01141
   H01142
   H01143
   H01144
   H01145
   H01146
   H01147
   H01148
 Total space available:  308.7G

fs_heartlab.2
 sort:path
 media: sf
 Volumes:
   H02042
   H02035
   H02036
   H02037
   H02038
   H02039
   H02040
   H02041
 Total space available:  641.2G

fs_lanv1.1
 Destination: disk2 (/darchive/data2)

fs_lanv1.2
 sort:path
 media: sg
 Volumes:
   L01000
   L01001
   L01002
   L01003
 Total space available:   92.7G

fs_lanv1.3
 sort:path
 media: sf
 Volumes:
   L02001
   L02002
 Total space available:  377.6G

fs_lanvision.1
 Destination: disk3 (/darchive/data3)

fs_lanvision.2
 sort:path
 media: sg
 Volumes:
   L01000
   L01001
   L01002
   L01003
 Total space available:   92.7G

fs_lanvision.3
 sort:path
 media: sf
 Volumes:
   L02001
   L02002
 Total space available:  377.6G

fs_original.1
 Destination: disk0 (/darchive/data)

fs_original.2
 sort:path
 media: sg
 Volumes:
   F01133
   F01134
   F01135
   F01136
   F01137
   F01138
   F01139
   F01140
 Total space available:  151.6G

fs_original.3
 sort:path
 media: sf
 Volumes:
   F02029
   F02030
   F02031
   F02032
   F02033
   F02034
   F02035
   F02036
   F02012
 Total space available:  796.1G

heartlab.1
 media: sf
 Volumes:
   STK000
 Total space available:   60.8G

lanv.1
 media: sf
 Volumes:
   STK000
 Total space available:   60.8G

lanv1.1
 media: sf
 Volumes:
   STK000
 Total space available:   60.8G

original1.1    Stopping here #
 media: sf
 Volumes:
   STK000
 Total space available:   60.8G

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams




   
 Dave Gray 
 [EMAIL PROTECTED] 
 omTo 
   beginners@perl.org  
 08/02/2005 02:46   cc 
 PM
   Subject 
   Re: reg exp using \G
 Please respond to 
 Dave Gray 
 [EMAIL PROTECTED] 
om
   
   




On 8/2/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 technically you are correct about escaping the dot, but in this
particular
 situation my regexp is working.  I will escape the dot.
 my goal again is to print from one sting to another from allsets
 down.  I apologize for the long output if data, but I want to reflect
100%
 accuracy.

 Any ideas on a simple for loop with a regexp?

for (ARC) {
  print if /one string/ .. /another/;
}

You already had that solution, though. What am I missing?

--
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: reg exp using \G

2005-08-02 Thread Dave Gray
On 8/2/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 yes but the problem is my start point and end point have identical entries
 under them.  It is stopping at original1.1 when I need for it to stop at
 the end of original1.1 and print
 
 media: sf
  Volumes:
STK000
  Total space available:   60.8G
 
 as opposed to just allsets to original1.1

Here's a test program that demonstrates how to do that.

#!/usr/bin/perl
use strict;
use warnings;

while (DATA) {
if (/AA/ ... /(CC)/) {
print;
if ($1) {
while (DATA) {
# this regex defines when your section is done
last if /^\s*$/;
print;
}
}
}
}

__DATA__
AA

BB

CC
DD
EE

FF
GG

HH
II

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




Re: reg exp using \G

2005-08-02 Thread Dave Gray
On 8/2/05, Dave Gray [EMAIL PROTECTED] wrote:
 On 8/2/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  yes but the problem is my start point and end point have identical entries
  under them.  It is stopping at original1.1 when I need for it to stop at
  the end of original1.1 and print
 
  media: sf
   Volumes:
 STK000
   Total space available:   60.8G
 
  as opposed to just allsets to original1.1
 
 Here's a test program that demonstrates how to do that.
 
 #!/usr/bin/perl
 use strict;
 use warnings;
 
 while (DATA) {
 if (/AA/ ... /(CC)/) {
 print;
 if ($1) {
 while (DATA) {
 # this regex defines when your section is done
 last if /^\s*$/;
 print;
 }

# so you don't have to spin over the rest of the file
last;

 }
 }
 }
 
 __DATA__
 AA
 
 BB
 
 CC
 DD
 EE
 
 FF
 GG
 
 HH
 II


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




Re: reg exp using \G

2005-08-02 Thread Jay Savage
Please don't top post. I think you've been asked this before.


On 8/2/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 ok I understand now...thanks, but I tried it and it is still stopping at
 original1.1
 I then modified it to print YE if ($1) but never saw YE in STDOUT.


Tha's because as a one liner it doesn't use parentheses. And also
becuase YES isn't a string, it's a constant. Do you have warnings
turned on? warnings and strict would catch these sorts of things.

print Yes if $1;   # or
if ($1) {print Yes}

Your choice.


  #!/usr/bin/perl
  use strict;
  use warnings;
 
  while (DATA) {
  if (/AA/ ... /(CC)/) {
  print;
  if ($1) {
  while (DATA) {
  # this regex defines when your section is done
  last if /^\s*$/;
  print;
  }
 
 # so you don't have to spin over the rest of the file
 last;
 
  }
  }
  }

I think we need a clearer description of what you want to do here. At
least I do. will your last line have original.1? Or will it have
something else? i don't think anyone knows what the end of
original.1 means. original.1 is a string, and the current code
matches that string. If you need to match the end of the string, use
'/original\.1$/'.

I think, though that you mean the end of some block of lines in your data file. 

It looks to me like you want something along the lines of :

  while() {
if (/allsets/ .. /original\.1/) {
  print;
} elsif (/media/ .. /Total/) {
  print;
}
  }

-- j
--
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org

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