Hi Monks,
I am changing/adding lines in bunch of files.
if $line is something. Change it to something else.
elsif $line is correct. leave it alone with next.
elsif $line isn't there. Put, it there.
If works,
elsif removes the $line if the $line is there.
elsif the line isn't there. Add it.
That works. But,the if/elsif/ also add there stuff too.
Then if I put else {next}; That Totally screws up the out file.
Can you tell me what is wrong?
Thanks!
#!/usr/bin/perl -w
use strict;
my $agent = "best1agent_start";
my $bgs=<<HERE;
'bgs')
/usr/bin/su - patrol /usr/adm/best1_default/bgs/scripts/best1collect
+ -q>>\$LOG 2>>\$LOG
;;
HERE
my $collect = " /usr/bin/su - patrol /usr/adm/best1_default/bgs/scr
+ipts/best1collect -q>>\$LOG 2>>\$LOG\n";
my $cf_dir = "/export/home/f358118/sysedge";
open SH_FILES, "sys.sh" or die "Error: $!";
my @sh_f=<SH_FILES>;
close SH_FILES;
foreach my $sh(@sh_f){
chomp $sh;
open(OUT, ">/$cf_dir/$sh".".OUT")or die "ERROR $!";
my $line;
open (SH, "$cf_dir/$sh") or die "ERROR $!";
while ($line = <SH>){
if($line =~ m/$agent/){
$line = $collect;
} elsif ( $line =~ m/best1collect/) {
next;
} elsif ($line =~ m/'syslogd'\)/){
my $newline = $. + 3;
$newline = $bgs;
print OUT "$newline\n";
}
#else { next };
print OUT $line;
print $line;
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.