On Apr 19, 6:58 pm, Mirco Wahab <wahab-m...@gmx.de> wrote:
> Nene wrote:
> > I wrote a perl script that opens a file. I wrote a regex that
> > captures $1 $2 and prints it to output. What I want it to do which I
> > can't figure out is to print the next line (which has a regex that I
> > need to capture as well) under the line that has the the regex but I
> > can't figure it out so far. Any help will be greatly appreciated.
>
> > #!/usr/bin/perl -w
> > use strict;
> > use diagnostics;
> > open( FILE, $ARGV[0] ) || die "can't open file!";
> > my @TEST = <FILE>;
> > foreach my $current_line (@TEST) {
> > if ($current_line =~ /^\S+ (\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}) \S+
> > \S+/) {
> > print "$1 $2\n";
> > ## But I also want to print a regex from the line underneath the
> > $current_line ###
>
> I don't really know what you mean with all these 'regex in the line's,
> but if you want to match regex_2 only after regex_1 matched a line
> before, then the following *could* work (depending on your data,
> which nobody knows).
>
> use strict;
> use warnings;
>
> open( my $fh, '<', shift ) or die "can't open file $!";
>
> my $cnt = 1;
> my $rg_1 = qr/^\S+ (\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}) \S+ \S+(?{$cnt=0})/;
> my $rg_2 = qr/(.)(.+)(?{$cnt=1})/;
>
> for( <$fh> ) {
> print "$1 $2\n" if /$rg_1/ || (!$cnt++ && /$rg_2/)
> }
> ...
>
> Maybe there are better solutions, but an
> understanding of your concrete problem
> would be the prerequisite ...
>
> Regards
>
> Mirco
Thank you for responding and I apologize for not being clear.
I want to print (2007-04-1

and (00:05:05) and I want to print where
(login_id = 'XSKW0010') which is the next line following this huge
select query.
Here is the data: (remember, everything from 00004C09 to 'restrict
ip' ) is one line.
00004C09 2007-04-18 00:05:05 12241 554188953 " select user.status,
user.user_id, user.company_id, isnull(t.detail1),'-1',t.detail1) as
ExpirationDate , if(isnull(t2.detail1),'0',t2.detail1) as inhouse,
c.company_status,c.company_name , a.line1 as address1 , a.city as
city ,a.state as state ,a.zip as zip, t3.detail1 as iprestricted from
hello.user as user , crapwise.company c LEFT JOIN crapwise.address a
ON c.main_address_id = a.address_id LEFT JOIN crapwise.tag_table t ON
t.user_id = user.user_id and t.company_id = user.company_id and
t.category = 'UserFlag' and t.sub_category = 'ExpirationDate' LEFT
JOIN crapwise.tag_table t2 ON t2.user_id = user.user_id and
t2.company_id = user.company_id and t2.category = 'User Options' and
t2.sub_category = 'InhouseSOAPUser' LEFT JOIN crapwise.tag_table t3
ON t3.company_id = user.company_id and t3.category =
'company security' and t3.sub_category = 'restrict ip'
where login_id = 'WSKW0010' and password = 'xxxxxxxxx' and
c.company_id =