in reply to insert line in between two lines
#perl linesBetween.pl linesBetweenTest.txt #makes backup just in case use strict; use warnings; my $infile = shift; $infile =~ /(.*)(\.txt$)/ or die 'Input file must be of type .txt'; my $backupfile = "$1.bak"; my $tmpfile = "$1.tmp"; `copy $infile $1.bak`; my $F; my %lines; open F, "< $infile" or die "couldn't open $infile"; open G, "> $tmpfile" or die "couldn't open $tmpfile"; while (<F>) { print G "$_\n"; } close F; close G; `del $infile`; `move $tmpfile $infile`;
|
|---|