#!/usr/local/bin/perl # repl.pl use strict; open INPUT, "<input.txt" or die "Blerch: $!\n"; open OUTPUT, ">output.txt" or die "Hcrelb: $!\n"; my $replace_string="Hi there.\n"; my $flag=0; my %markers=("BEGIN" => "<!- Begin Replacable Section-->", "END" => "<!- End Replacable Section-->", ); while (<INPUT>) { if ($flag) { next unless /$markers{END}/; $flag=0; print OUTPUT $replace_string; } print OUTPUT; $flag=1 if /$markers{BEGIN}/; } __END__ > cat input.txt But now I know that twenty centuries of stony sleep were vexed to nightmare by a rocking cradle. And what rough beast, it's hour come round at last, slouches towards Betlehem to be born? <!- Begin Replacable Section--> A poem <!- End Replacable Section--> W. B. Yeats > repl.pl ; cat output.txt But now I know that twenty centuries of stony sleep were vexed to nightmare by a rocking cradle. And what rough beast, it's hour come round at last, slouches towards Betlehem to be born? <!- Begin Replacable Section--> Hi there. <!- End Replacable Section--> W. B. Yeats
CU
Robartes-
In reply to Re: Modifying A Bunch of Files by replacing specific lines
by robartes
in thread Modifying A Bunch of Files by replacing specific lines
by ishaqali
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |