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

Getting the right output 3

Status
Not open for further replies.

sunixadm

Technical User
Sep 20, 2001
73
DE
Hi,

I have a text file with this content:

vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool
(C) Copyright 2001 Microsoft Corp.

Contents of shadow copy set ID: {bcfa443a-2977-4ca1-880b-2403044e9b84}
Contained 1 shadow copies at creation time: 8/2/2005 7:45:01 AM
Shadow Copy ID: {bd423380-bee9-40a4-a592-61cc9a3fa25e}
Original Volume: (E:)\\?\Volume{a8375e45-0323-11d9-8bae-505054503030}\
Shadow Copy Volume: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy6
Provider: 'Microsoft Software Shadow Copy provider 1.0'
Type: ClientAccessible
Attributes: Persistent, Client-accessible, No auto release, No writers, Differential

Contents of shadow copy set ID: {6bfcbdf7-7d73-4b97-9119-1072ae5d8d40}
Contained 1 shadow copies at creation time: 8/2/2005 8:00:03 AM
Shadow Copy ID: {4ea692f9-5583-460b-97b4-df9b373950bb}
Original Volume: (E:)\\?\Volume{a8375e45-0323-11d9-8bae-505054503030}\
Shadow Copy Volume: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy7
Provider: 'Microsoft Software Shadow Copy provider 1.0'
Type: ClientAccessible
Attributes: Persistent, Client-accessible, No auto release, No writers, Differential

Contents of shadow copy set ID: {01ebf7e2-414d-41c0-9d61-c9425b3814f0}
Contained 1 shadow copies at creation time: 8/2/2005 8:15:02 AM
Shadow Copy ID: {f1894607-d53d-4501-837a-e9060d4458c9}
Original Volume: (E:)\\?\Volume{a8375e45-0323-11d9-8bae-505054503030}\
Shadow Copy Volume: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy8
Provider: 'Microsoft Software Shadow Copy provider 1.0'
Type: ClientAccessible
Attributes: Persistent, Client-accessible, No auto release, No writers, Differential

Contents of shadow copy set ID: {15154c47-84e4-4759-ad45-96779483152b}
Contained 1 shadow copies at creation time: 8/2/2005 8:30:01 AM
Shadow Copy ID: {e431ebc9-88f6-4e7b-a02f-4de67f6ecef2}
Original Volume: (E:)\\?\Volume{a8375e45-0323-11d9-8bae-505054503030}\
Shadow Copy Volume: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy9
Provider: 'Microsoft Software Shadow Copy provider 1.0'
Type: ClientAccessible
Attributes: Persistent, Client-accessible, No auto release, No writers, Differential

And am looking for the Shadow Copy ID with time stamps of 8:15, 12:15 and 16:15.

My script stops after find the Shadow Copy ID for 8:15 and I can't figure out why....

Her is my code:

#!/usr/bin/perl
unless (open(FILE1, "files/shadow-list.txt")) {

if (-e "files/shadow-list.txt") {

die ("File files/shadow-list.txt exists, but cannot be opened.\n");

} else {

die ("File files/shadow-list.txt does not exist.\n");

}

}

$line = <FILE1>;

@words = ("8:15", "12:15", "16:15");

foreach $word (@words) {

while ($line ne "") {

if ($line =~ /$word/) {

$line = <FILE1>;
print ($line);
} else {
$line = <FILE1>;
}
}
}


My output is:
Shadow Copy ID: {f1894607-d53d-4501-837a-e9060d4458c9}

But all I reall need is:

{f1894607-d53d-4501-837a-e9060d4458c9}

But for all three times.

Thanks for the help!

-Joe
 
Code:
open FH, "<"files/shadow-list.txt" or die "Can't open file";
@words = ("8:15", "12:15", "16:15");
while (<FH>) {
  $line=$_;
  foreach $word (@words)
    if ($line =~/$word/) {
      $next_line=<FH>;
      ($crap,$data)=split /\:/, $next_line; #not sure if this needs escaping or not :(
      print "$data\n";
    }
  }
}

cigless ...
 
Hi Paul,

I tried your code and got:

Bareword found where operator expected at ./new.pl line 2, near ""<"files"
(Missing operator before files?)
String found where operator expected at ./new.pl line 2, near "txt" or die ""
Bareword found where operator expected at ./new.pl line 2, near "" or die "Can't"
(Missing operator before Can't?)
Number found where operator expected at ./new.pl line 3, near "@words = ("8"
(Might be a runaway multi-line "" string starting on line 2)
(Missing operator before 8?)
String found where operator expected at ./new.pl line 3, near "15", ""
(Missing operator before ", "?)
Number found where operator expected at ./new.pl line 3, near "", "12"
(Missing operator before 12?)
String found where operator expected at ./new.pl line 3, near "15", ""
(Missing operator before ", "?)
Number found where operator expected at ./new.pl line 3, near "", "16"
(Missing operator before 16?)
String found where operator expected at ./new.pl line 10, near "print ""
(Might be a runaway multi-line "" string starting on line 3)
(Missing semicolon on previous line?)
Scalar found where operator expected at ./new.pl line 10, near "print "$data"
(Do you need to predeclare print?)
Backslash found where operator expected at ./new.pl line 10, near "$data\"
(Missing operator before \?)
String found where operator expected at ./new.pl line 10, at end of line
(Missing semicolon on previous line?)
syntax error at ./new.pl line 2, near ""<"files"
Can't find string terminator '"' anywhere before EOF at ./new.pl line 10.


Thanks.

-Joe
 
sunixadm,
the first line in Paul's code have an extra " in it, remove the one after the <.

open FH, "<files/shadow-list.txt" or die "Can't open file";
@words = ("8:15", "12:15", "16:15");
while (<FH>) {
$line=$_;
foreach $word (@words)
if ($line =~/$word/) {
$next_line=<FH>;
($crap,$data)=split /:/, $next_line;
print "$data\n";
}
}
}
 
Code:
@times = qw( 8:15 12:15 6:15 );

foreach $time (@times) {
  m/${time}:\d{2} [APM]{2}.      Shadow Copy ID: ({[^}]+})/s;
  print "$1\n";
}

you will need to load the entire file into the $_ variable using this syntax:-

undef $/;
$_ = <FILEHANDLE>;
$/ = "\n";


Kind Regards
Duncan
 
Thanks to everyone who responded. I've not only found a solution to my problem, I've also learned something new!

Thanks!

-Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top