N
Nene
I used the same code below (provided by Randy) to do in place edits on
a config file and it works great, but I when I try to use the same
code for an html file, it does not work.
###Below is the code###
#!/usr/bin/perl -w
use strict;
use warnings;
my $stuff = "</tr>";
my $a = "insert_text_here\n";
{
local @ARGV = "misc.txt";
local $^I = ".bak"; # appended to the backup copy
while (<>) {
if ((/$stuff/..!/$stuff/) =~ /E/) { # if we're at the end of
the Listens
$_ = $a . $_; # prepend the line to the next line
}
print; # but print whatever we have
}
}
###Below is the result of the script when I run it#
<tr>
<td>http://xxx.xxx.xxx.xxx</td>
<td>
<a href='https://xxx:8002'>
https://xxx.xxx.xxx.xxx:8002
</a>
</td>
</tr>
insert_text_here
<tr>
<td>http://xxx.xxx.xxx.xxx</td>
<td>
<a href='https://xxx.xxx:8010'>
https://xxx.xxx.xxx:8010
</a>
</td>
</tr>
insert_text_here
<tr>
<td>http://xxx.xxx.xxx.xxx:8145</td>
<td>
<a href='https://xxx.xxx.xxx:8148'>
https://xxx.xxx.xxx:8148
</a>
</td>
</tr>
insert_text_here
Text in this line
Text in this line
Text in this line
####
As you can see "insert_text_here" is appended at the bottom of every
"</tr>"; I only want it appended to the last "</tr>".
If this is not possible, is there a module that will read a specific
number of lines backwards and then insert?
a config file and it works great, but I when I try to use the same
code for an html file, it does not work.
###Below is the code###
#!/usr/bin/perl -w
use strict;
use warnings;
my $stuff = "</tr>";
my $a = "insert_text_here\n";
{
local @ARGV = "misc.txt";
local $^I = ".bak"; # appended to the backup copy
while (<>) {
if ((/$stuff/..!/$stuff/) =~ /E/) { # if we're at the end of
the Listens
$_ = $a . $_; # prepend the line to the next line
}
print; # but print whatever we have
}
}
###Below is the result of the script when I run it#
<tr>
<td>http://xxx.xxx.xxx.xxx</td>
<td>
<a href='https://xxx:8002'>
https://xxx.xxx.xxx.xxx:8002
</a>
</td>
</tr>
insert_text_here
<tr>
<td>http://xxx.xxx.xxx.xxx</td>
<td>
<a href='https://xxx.xxx:8010'>
https://xxx.xxx.xxx:8010
</a>
</td>
</tr>
insert_text_here
<tr>
<td>http://xxx.xxx.xxx.xxx:8145</td>
<td>
<a href='https://xxx.xxx.xxx:8148'>
https://xxx.xxx.xxx:8148
</a>
</td>
</tr>
insert_text_here
Text in this line
Text in this line
Text in this line
####
As you can see "insert_text_here" is appended at the bottom of every
"</tr>"; I only want it appended to the last "</tr>".
If this is not possible, is there a module that will read a specific
number of lines backwards and then insert?