469,890 Members | 2,164 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

rewrite N lines in Perl

Hello all,

I am trying to write a script (without much luck) that will modify certain
lines in a sendmail file. Here is what is in the file:

SMailerToTriple=95
R< > $* $@ $1 strip off null relay
R< error : $-.$-.$- : $+ > $* $#error $@ $1.$2.$3 $: $4
R< error : $- : $+ > $* $#error $@ $(dequote $1 $) $: $2
R< error : $+ > $* $#error $: $1
R< local : $* > $* $>CanonLocal < $1 > $2
dnl it is $~[ instead of $- to avoid matches on IPv6 addresses
R< $~[ : $+ @ $+ > $*<$*>$* $# $1 $@ $3 $: $2<@$3> use literal user
R< $~[ : $+ > $* $# $1 $@ $2 $: $3 try qualified mailer
R< $=w > $* $@ $2 delete local host
R< $+ > $* $#_RELAY_ $@ $1 $: $2 use unqualified
mailer

I need it rewritten as:

SMailerToTriple=95
R< > $* $@ $1 strip off null relay
CUSTOM LINE #1
R< error : $- : $+ > $* $#error $@ $(dequote $1 $) $: $2
R< error : $+ > $* $#error $: $1
R< local : $* > $* $>CanonLocal < $1 > $2
dnl it is $~[ instead of $- to avoid matches on IPv6 addresses
R< $~[ : $+ @ $+ > $*<$*>$* $# $1 $@ $3 $: $2<@$3> use literal user
CUSTOM LINE #2
CUSTOM LINE #3
R< $~[ : $+ > $* $# $1 $@ $2 $: $3 try qualified mailer
R< $=w > $* $@ $2 delete local host
R< $+ > $* $#_RELAY_ $@ $1 $: $2 use unqualified
mailer
Can anyone point me in the right direction as I'm having a real hard time
making this fly.

Thank you,

Bfons

Jul 19 '05 #1
4 2050

Your description is a bit vague. If all you need to do is change line 3 and
add 2 lines after line 8, then just count lines as you read them and take
the appropriate action when line numer = 3 or 8. If there is some other
criteria that you are using to determine where to change/insert lines, then
please explain it.
"Bfons" <li*******@usermail.com> wrote in message
news:7a******************************@news.teranew s.com...
Hello all,

I am trying to write a script (without much luck) that will modify certain
lines in a sendmail file. Here is what is in the file:

SMailerToTriple=95
R< > $* $@ $1 strip off null relay R< error : $-.$-.$- : $+ > $* $#error $@ $1.$2.$3 $: $4
R< error : $- : $+ > $* $#error $@ $(dequote $1 $) $: $2
R< error : $+ > $* $#error $: $1
R< local : $* > $* $>CanonLocal < $1 > $2
dnl it is $~[ instead of $- to avoid matches on IPv6 addresses
R< $~[ : $+ @ $+ > $*<$*>$* $# $1 $@ $3 $: $2<@$3> use literal user
R< $~[ : $+ > $* $# $1 $@ $2 $: $3 try qualified mailer R< $=w > $* $@ $2 delete local host
R< $+ > $* $#_RELAY_ $@ $1 $: $2 use unqualified
mailer

I need it rewritten as:

SMailerToTriple=95
R< > $* $@ $1 strip off null relay CUSTOM LINE #1
R< error : $- : $+ > $* $#error $@ $(dequote $1 $) $: $2
R< error : $+ > $* $#error $: $1
R< local : $* > $* $>CanonLocal < $1 > $2
dnl it is $~[ instead of $- to avoid matches on IPv6 addresses
R< $~[ : $+ @ $+ > $*<$*>$* $# $1 $@ $3 $: $2<@$3> use literal user
CUSTOM LINE #2
CUSTOM LINE #3
R< $~[ : $+ > $* $# $1 $@ $2 $: $3 try qualified mailer R< $=w > $* $@ $2 delete local host
R< $+ > $* $#_RELAY_ $@ $1 $: $2 use unqualified
mailer
Can anyone point me in the right direction as I'm having a real hard time
making this fly.

Thank you,

Bfons

Jul 19 '05 #2

"Kris Wempa" <calmincents(NO_SPAM)@yahoo.com> wrote in message
news:bk*********@kcweb01.netnews.att.com...

Your description is a bit vague. If all you need to do is change line 3 and add 2 lines after line 8, then just count lines as you read them and take
the appropriate action when line numer = 3 or 8. If there is some other
criteria that you are using to determine where to change/insert lines, then please explain it.


Each version of Sendmail will have these lines in different places. For
example in the latest version, this ruleset is at line 1294 in the proto.m4
file. In the next version, this ruleset will more than likely be somewhere
else. Up until now, we have been editing it by hand but are tired of doing
this. We need the script to determine where SMailerToTriple=95 is in
proto.m4, and from there make the necessary changes.

Thank you in advance,

Bfons
Jul 19 '05 #3
I'm not sure I completely understand what you need to do. However, if you
just need to identify those lines and change/add custom lines, you could
just use a script such as this:

open(FILE, "< sendmailfile");
opend(NEWFILE, "> newsendmailfile");
while ($line = <FILE>) {

if ($line =~ /^R< error : \$\-\.\$\-\.\$\- : \$\+ > \$\* \$$/) { # if
matched the first line to be changed
print NEWFILE "CUSTOM LINE #1\n";
} else {
if ($line =~ /^R< \$~\[ : \$+ \@ \$\+ > \$\*<\$\*>\$\* \$$/) {
#if matched the second line
print NEWFILE $line; # print the line
print NEWFILE "CUSTOM LINE #2\n"; # add the 2 additional lines
print NEWFILE "CUSTOM LINE #3\n";

} else {
print NEWFILE $line; # if no match, just copy the exact line
}
}
}
close(FILE);
close(NEWFILE);

This will create a new, modified sendmail file from the original one. Is
this what you are trying to do ???

"Bfons" <li*******@usermail.com> wrote in message
news:ab******************************@news.teranew s.com...

"Kris Wempa" <calmincents(NO_SPAM)@yahoo.com> wrote in message
news:bk*********@kcweb01.netnews.att.com...

Your description is a bit vague. If all you need to do is change line 3 and
add 2 lines after line 8, then just count lines as you read them and take the appropriate action when line numer = 3 or 8. If there is some other
criteria that you are using to determine where to change/insert lines,

then
please explain it.


Each version of Sendmail will have these lines in different places. For
example in the latest version, this ruleset is at line 1294 in the

proto.m4 file. In the next version, this ruleset will more than likely be somewhere else. Up until now, we have been editing it by hand but are tired of doing this. We need the script to determine where SMailerToTriple=95 is in
proto.m4, and from there make the necessary changes.

Thank you in advance,

Bfons

Jul 19 '05 #4

"Kris Wempa" <calmincents(NO_SPAM)@yahoo.com> wrote in message
news:bk*********@kcweb01.netnews.att.com...
I'm not sure I completely understand what you need to do. However, if you
just need to identify those lines and change/add custom lines, you could
just use a script such as this:

open(FILE, "< sendmailfile");
opend(NEWFILE, "> newsendmailfile");
while ($line = <FILE>) {

if ($line =~ /^R< error : \$\-\.\$\-\.\$\- : \$\+ > \$\* \$$/) { # if matched the first line to be changed
print NEWFILE "CUSTOM LINE #1\n";
} else {
if ($line =~ /^R< \$~\[ : \$+ \@ \$\+ > \$\*<\$\*>\$\* \$$/) {
#if matched the second line
print NEWFILE $line; # print the line
print NEWFILE "CUSTOM LINE #2\n"; # add the 2 additional lines
print NEWFILE "CUSTOM LINE #3\n";

} else {
print NEWFILE $line; # if no match, just copy the exact line
}
}
}
close(FILE);
close(NEWFILE);

I need to add the three lines (one on top and two a couple of lines down).
It looks like you gave me something good to go on.

Thank you,

Bfons
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Ling Lee | last post: by
2 posts views Thread by Andrew Rich | last post: by
6 posts views Thread by Larry Doan | last post: by
26 posts views Thread by Shannon Jacobs | last post: by
82 posts views Thread by Edward Elliott | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.