473,473 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2195

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
2
by: Andrew Rich | last post by:
Howdy, I have a need to do this :- 1. find a match 2. go back three lines 3. read out lines 1 2 3 eg
6
by: Larry Doan | last post by:
In a shell script or Perl, how do I open a file, find what I'm looking then Case 1: grab that line + the next 2 lines Case 2: grab that line + the previous 2 lines? TIA, Larry
26
by: Shannon Jacobs | last post by:
Sorry to ask what is surely a trivial question. Also sorry that I don't have my current code version on hand, but... Anyway, must be some problem with trying to do the negative. It seems like I get...
24
by: Nalla | last post by:
Hi, I want a program. It should be a command line one. you can input the path of a folder(preferably) or a file...it should count the no. of lines between the compiler directives, ifdef win32 and...
82
by: Edward Elliott | last post by:
This is just anecdotal, but I still find it interesting. Take it for what it's worth. I'm interested in hearing others' perspectives, just please don't turn this into a pissing contest. I'm in...
15
by: Yogi | last post by:
Hi there, I have a quick question. In my html document, I want to make a new paragraph whenever I have a blank line in the html source. Using <p> and </pevery time is kind of cumbersome (I want...
3
by: dirknrw | last post by:
Hi, I have a tricky question!? :-) I'm using the perl -e command in order to match lines between two search patterns. The problem I have is, for the first example it is working, for the second...
1
by: msxi | last post by:
Hi, I have s sed script that removes the following lines from a db dump file. I would like to remove these lines using perl. Could anybody assist? /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.