Here is my code. I wish to extract part of the text and write into another file. The loop of the code do not stop at my selected range of text. It read until the final match line of word. Please advise me. Thanks. For example, I need to extract the $ NAME: sandy until $$.TO and then join with the contents inside $NAME: patrick which is start from G1 until $$SRU.
TEXT:
$ NAME : corry
$$.Inc s d
$$.Oc s
$$.TO
G1 ty n1 EE EE M T1 T2 $$SRU
G2 n1 y OO OO M T3 T4 $$SRU
$$.EON
$ NAME : patrick
$$.Inc c d
$$.Oc c
$$.TO
G1 td n3 EE EE M T5 T6 $$SRU
G2 n3 y OO OO M T7 T8 $$SRU
$$.EON
$ NAME : sandy
$$.Inc k l
$$.Oc l
$$.TO
G1 td n3 FF FF M R5 R6 $$SRU
G2 n3 y OO OO N R7 R8 $$SRU
$$.EON
CODE:
use strict;
use warnings;
open my $F1, '<', 'testing.txt' or die "failed $!";
open my $F2, '>', 'out.txt' or die "failed $!";
while (<$F1>) {
if (/^\$ NAME : sandy/../\$.TO/) {
print $F2 $_;
}
if (/^\$ NAME : patrick/../\$.EON/) {
if(/^G1/../\$SRU){
s/G1/G1.G1o.n/g;
print $F2 $_;}
}
}
close $F1;
close $F2;