Koozali.org: home of the SME Server

Perl search & replace

Craig Foster

Perl search & replace
« on: July 16, 2003, 09:49:15 AM »
I'm trying to rem out the existing SMTP port in /etc/services
I've created /etc/e-smith/templates-custom/etc/services/S50remoldsmtp with the following contents

{
    # Obsolete the existing smtp port
    @lines = grep { !/^smtp/ } @lines;
    "# SMTP Was Here ";
}

the fragments all add to @lines and get written out as the last action.
This is based on the appletalk fragment for modules.conf.

Have I missed something, or is this mental block not just me?...


Craig F.

Jon Blakely

Re: Perl search & replace
« Reply #1 on: July 16, 2003, 10:02:41 AM »
Craig,

I have used the following command in scripts to search and replace.

This info care of Darrell Mays How To.

In the example shown below you want to open the file named /root/test.txt, search for the word e-smith and replace it with the word mitel.  In addition, the command creates a backup of the original file with the extension .bkup.  In this case it creates /root/test.txt.bkup.

perl -n -i.bkup -e 's/e-smith/mitel/i; print;' /root/test.txt

Jon

Charlie Brady

Modifying /etc/services (was Re: Perl search & replace)
« Reply #2 on: July 16, 2003, 07:01:00 PM »
Craig Foster wrote:

> I'm trying to rem out the existing SMTP port in /etc/services

That's not a wise thing to do. /etc/services defines *standard* ports for services, so shouldn't be arbitrarily changed. If you want to run a particular service on a non-standard port, then it's almost certain that you can explicitly specify the port number in that application's configuration. You can usually do this by substituting nnnn for "smtp".

Charlie