#!/usr/bin/perl
while(<DATA>){
if (/\{TT\}/ .. /^\{TAG\}/)
{
unless (/^\{(TT|TAG)\}/)
{
$deletestrings = $_;
#if($_ =~ m/^D$/){
print $_;
open FILE, '>list.txt';
print FILE $_;
close FILE;
$_ = '' if index( $_, "$deletestrings" ) >= 0;
}
}
}
__DATA__
S 9912290449 00005941^B{TT}
D
{TAG}
9912290449
{PUBLICATION}
THE OS
{DATE}
000101
S 9912290450 00005941^B{TT}
R
{TAG}
9912290450
{DATE}
000101
{TDATE}
Saturday, January 1, 2000
S 9912290451 00005941^B{TT}
D
{TAG}
9912290451
{DATE}
000101
{TDATE}
Saturday, January 1, 2000
Now the above writes the lines which is between {TT} and {TAG}.
The output is
S 9912290449 00005941^B{TT}
D
S 9912290450 00005941^B{TT}
R
S 9912290451 00005941^B{TT}
D
How to write only two lines which has the character D to the file.
In the file:
only
S 9912290449 00005941^B{TT}
D
S 9912290451 00005941^B{TT}
D
should be writeen |