Solved

Problem on multiple splits

Posted on 2003-12-02
4
339 Views
Last Modified: 2008-03-17
this code is for monitoring netbackup jobs. Here is a portion of my code:

$error=`/usr/openv/netbackup/bin/admincmd/bperror -l -t backstat -d $newtime`;

print ALLERROR "$error\n";
close(ALLERROR);

open(ALLERROR,"$all_errors") || die "Can't open infile: $!\n";

while(<ALLERROR>){

 ($junk1, $junk2, $junk3, $junk4, $media, $dt, $junk7, $junk8, $client, $junk10, $junk11, $junk12, $junk13, $policy, $junk15, $schedule, $junk17, $junk18, $nbstatus) =split(" ",$_);

############################ Start: Find Oracle jobs and their owners ########################################################

if  ( $nbstatus==0 | nbstatus==1 && $schedule =~  "ORACLE" )  {
                                                             
next if /^(\s)*$/;  # skip blank lines

@owner=`/usr/openv/netbackup/bin/admincmd/bpdbjobs -report -all_columns | grep $dt | grep -v grep | awk -F',' '{print $20}'`;

 ($jk1, $jk2, $jk3, $jk4, $jk5, $jk6, $jk7, $jk8, $jk9, $jk10, $jk11, $jk12, $jk13, $jk14, $jk15, $jk16, $jk17, $jk18, $jk19, $own) =split(/\,/,$_);


The first split works. The second splitl does not. For the second split I only what the 20th field, $own. However if I do a print $jk1 I get the entire line for the frist split, ie

junk1, $junk2, $junk3, $junk4, $media, $dt, $junk7, $junk8, $client, $junk10, $junk11, $junk12, $junk13, $policy, $junk15, $schedule, $junk17, $junk18, $nbstatus


Thougths?


0
Comment
Question by:MatthewF
  • 2
4 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 9862372
$_ will still be set to the contents of the curre line in file ALLERROR. What data do you want to use for the second split?
Also, it is quicker to say:
(@values) =split(/\,/,$_);
$last_value = pop(values); # get last value of array


0
 

Author Comment

by:MatthewF
ID: 9862966
The second split:
@owner=`/usr/openv/netbackup/bin/admincmd/bpdbjobs -report -all_columns | grep $dt | grep -v grep | awk -F',' '{print $20}'`;

 ($jk1, $jk2, $jk3, $jk4, $jk5, $jk6, $jk7, $jk8, $jk9, $jk10, $jk11, $jk12, $jk13, $jk14, $jk15, $jk16, $jk17, $jk18, $jk19, $own) =split(/\,/,$_);


I want to return $own. I didnt try to use a pop becuase the array of owener is generally 30+ fields, not all which are always populated. ie
The first 10 fields

1,2,3,4,,6,7,8,9,10,
or
1,2,3,4,,6,,8,,10,

etc, etc

0
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 175 total points
ID: 9863056
The problem is you are not linking @owner to the data to split on, its still using the current line
form the filehandle. I think you may want something like:

$owner=`/usr/openv/netbackup/bin/admincmd/bpdbjobs -report -all_columns | grep $dt | grep -v grep | awk -F',' '{print $20}'`;

 ($jk1, $jk2, $jk3, $jk4, $jk5, $jk6, $jk7, $jk8, $jk9, $jk10, $jk11, $jk12, $jk13, $jk14, $jk15, $jk16, $jk17, $jk18, $jk19, $own) =split(/\,/,$owner);

0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 75 total points
ID: 9863894
#It's also easier to say
$own = (split/\,/,$owner)[19];
 
($media, $dt, $client, $policy, $schedule, $nbstatus)=(split)[5,6,9,14,16,19];
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question