Thread Teil einer Datei kopieren....Lösungswege?
(4 answers)
Opened by crojay at 2011-09-15 22:15 Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 #!/usr/bin/perl use strict; use warnings; my $infile ='test.dat'; my $outfile='out.dat'; my $search ='[HKEY_LOCAL_MACHINE\SOFTWARE\OJ\TEST2]'; my $outstr; { open(my $fh, '<', $infile) or die(qq'ERROR open "$infile" ($!)\n'); # Zeilenende auf "\n\n" setzen local $/="\n\n"; while(my $block=<$fh>) { if($block=~/\Q$search\E/) { $outstr=$block; last; } } close($fh); } die(qq'Key "$search" not found in $infile') unless($outstr); { open(my $fh, '>', $outfile) or die(qq'ERROR open "$outfile" ($!)\n'); print $fh $outstr; close($fh); } Last edited: 2011-09-15 23:14:37 +0200 (CEST) |