1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[HKEY_LOCAL_MACHINE\SOFTWARE\OJ\TEST1]
"AllowMultilineFieldsInJob"="False"
"AmountRetries"="3"
"CPATTimeOutSeconds"="300"
[HKEY_LOCAL_MACHINE\SOFTWARE\OJ\TEST2]
"AllowMultilineFieldsInJob"="False"
"AmountRetries"="3"
"CPATTimeOutSeconds"="300"
[HKEY_LOCAL_MACHINE\SOFTWARE\OJ\TEST3]
"AllowMultilineFieldsInJob"="False"
"AmountRetries"="3"
"CPATTimeOutSeconds"="300"
[HKEY_LOCAL_MACHINE\SOFTWARE\OJ\TEST4]
"AllowMultilineFieldsInJob"="False"
"AmountRetries"="3"
"CPATTimeOutSeconds"="300"
1
2
3
4
[HKEY_LOCAL_MACHINE\SOFTWARE\OJ\TEST2]
"AllowMultilineFieldsInJob"="False"
"AmountRetries"="3"
"CPATTimeOutSeconds"="300"
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); }
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
#!/usr/bin/perl use strict; use warnings; my @reg = do { local $/ = "\n\n"; <DATA> }; for my $regentry (@reg) { print $regentry if $regentry =~ m/TEST2/; } __DATA__ [HKEY_LOCAL_MACHINE\SOFTWARE\OJ\TEST1] "AllowMultilineFieldsInJob"="False" "AmountRetries"="3" "CPATTimeOutSeconds"="300" [HKEY_LOCAL_MACHINE\SOFTWARE\OJ\TEST2] "AllowMultilineFieldsInJob"="False" "AmountRetries"="3" "CPATTimeOutSeconds"="300" [HKEY_LOCAL_MACHINE\SOFTWARE\OJ\TEST3] "AllowMultilineFieldsInJob"="False" "AmountRetries"="3" "CPATTimeOutSeconds"="300" [HKEY_LOCAL_MACHINE\SOFTWARE\OJ\TEST4] "AllowMultilineFieldsInJob"="False" "AmountRetries"="3" "CPATTimeOutSeconds"="300"