Hey guys,
I know you can do one a liner that appends a string after line in a
file:
ie: perl -p -i -e 's/$oldsting/$1\n$nextline/' file.txt
But I was doing it in a script:
#!/usr/bin/perl
use strict;
my $conf = "/home/bob/my.cnf";
my $string = "mysqld]";
my $replace = "bob was here";
open (FILE, "$conf") or die "can not open $conf: $!\n";
my @file = <FILE>;
close (FILE);
for (my $line = 0; $line <= $#file; $line++)
{
$/ = '[';
if ($file[$line] =~ /$string$/)
{
$file[$line] .= "$replace";
last;
}
}
open (FILE, ">$conf") or die "can not open
$conf: $!\n";
print FILE @file;
close (FILE);
Then I was thinking, there has got to be a better way of doing this..
Any suggestions
Thanks,
Chad
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]