LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-14-2002, 10:44 AM   #1
360
Member
 
Registered: Jun 2001
Distribution: FC4
Posts: 136

Rep: Reputation: 15
Question sed question


I am trying to change every instance of an ip address in my apache conf file to a different ip address.

What type of shell redirection do I use to make sed write the subtitutes to the same conf file?

Here is the command I am using to substitue:
sed -n 's/209.25.242.73/66.40.144.22/gp' httpd.conf

Thanks
 
Old 03-14-2002, 09:18 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Either use vi or write to a tmp file.
 
Old 03-15-2002, 09:52 AM   #3
lavelle
LQ Newbie
 
Registered: Mar 2001
Location: Dallas TX
Distribution: RH7.2 RH7.0
Posts: 12

Rep: Reputation: 0
use perl

Redirection from a file to the same file usually results in an empty or close to empty file. Perl is great for this activity, for example:

perl -i.old -pe 's/192\.168\.1\.2/10\.10\.10\.10/g' httpd.conf

The -i.old will move the original file to .old in the event you break it. WARNING: run the command twice and your backup is overwritten.

The -pe is actually 2 flags the p is an implied print loop over every line in the file and the e 'code' indicates you are giving perl the code on the command line. Note the g in the end of the code, if you leave this off then a line like this:
192.168.1.2 happy fun 192.168.1.2
will end up looking like:
10.10.10.10 happy fun 192.168.1.2
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed question ckoniecny Linux - General 3 11-11-2005 09:31 AM
question on sed tifu Linux - Newbie 3 03-18-2005 04:38 PM
sed question virendratp Programming 3 09-10-2004 03:21 AM
little sed question freelinuxcpp Linux - Software 3 01-20-2004 07:36 AM
sed question zoomzoom Linux - Software 2 10-20-2003 04:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration