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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File path extraction from output

Status
Not open for further replies.

mbach

Technical User
Dec 12, 2000
24
US
All,

I need to extract all windows file paths from a piped output
but some file paths (ie...C:\winnt\my documents\...)have
spaces in the path. The file paths can be found in the output in between the following strings....."file:" and "(WIN32" and/or a series of numbers (04/03/03 and/or 98822341). Can Perl extract the file paths even with embedded spaces?
Thanks!!!
Mike
 
Can you post a sample of the output, also what do you intend to do with the extracted information?

Paul
 
Paulteg,

I am using a NetBackup bperror command. bperror -problems
| grep swmn047. I want the file paths to be listed in a file which will then be read and the failed files will be automatically reran by another script via a netbackup command. Here is the output....
1054170166 1 4 8 nbm1 288230 288230 0 swmn047.spgl.com bpbrm from client swmn047.spgl.com: WRN - can't open file: E:\Program Files\TCS\RTA\Docs\NNI-CSTEMP\Dbfs\DKHBECNU.LCK (WIN32 32: The process cannot access the file because it is being used by another process. )
1054170170 1 4 8 nbm1 288230 288230 0 swmn047.spgl.com bpbrm from client swmn047.spgl.com: WRN - can't open file: E:\Program Files\TCS\RTA\Docs\SGTSNB-JXCGEAR\Dbfs\DKGPZYRQ.LCK (WIN32 32: The process cannot access the file because it is being used by another process. )
1054170172 1 4 8 nbm1 288230 288230 0 swmn047.spgl.com bpbrm from client swmn047.spgl.com: WRN - can't open file: E:\Program Files\TCS\RTA\Docs\SGTSNB-SAINT JOHN OPERATIONS\Dbfs\DKGXMKS3.LCK (WIN32 32: The process cannot access the file because it is being used by another process. )
1054170174 1 4 16 nbm1.spgl.com 288230 288230 0 swmn047.spgl.com bpsched backup of client swmn047.spgl.com exited with status 1 (the requested operation was partially successful)
 
Something along these lines

Code:
if (index $line, "WRN - can't open file" != -1) {
  #this is a line we want
  $file = trim(substr $line, 114, (index $line, "(WIN32) - 114)
}

sub trim {
    my @out= @_;
    for (@out) {
        s/^\s+//;
        s/\s+$//;
    }
    return wantarray ? @out : $out[0];
}

There are regexes that will pull what you want, but given that you know the origin of the affected file, and you can easily determine the end of the file "(WIN32", there's no real percentage in loading the regex engine - to my mind any way

This isn't tested, but should work, and any assumptions are based on the sample extract you provided.

HTH
PAul
 
well, sure the regex engine has some load cost to it but it's not as much as people think. Also, it's sometimes worth the extra load if it simplifies the code a lot. Personnaly I'd go with a regex on that one. The regex could look like this;

For a single path:
($path) = $input =~ /file:(.+?)\(WIN32/i;

For an array of paths:
@paths = $input =~ /file:(.+?)\(WIN32/ig;

I guess it's another case for Benchmark. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top