LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-06-2010, 01:21 PM   #1
greipr
LQ Newbie
 
Registered: Oct 2010
Posts: 1

Rep: Reputation: 0
using sed to send a variable and replace


Hi! I can't figure out the exact sed to make this work. I've installed CentOS and am trying to pass variables to a network-config file.

variables:
$ipAddress
$netmask
$gateway

file:
DeviceList.Ethernet.eth0.IP=192.168.1.10
DeviceList.Ethernet.eth0.Netmask=255.255.255.0
DeviceList.Ethernet.eth0.Gateway=192.168.1.1

I'm looking to replace the eth0.IP=*.*.*.* with eth0.IP=$ipAddress, and so on for netmask and gateway. How could I get this to work?
 
Old 10-06-2010, 02:07 PM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Hi,
try this
Code:
sed -i -r "s/(eth0\.IP=)[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/\1$ipAddress/" filename
[EDIT]
A bit more elegant
Code:
sed -i -r "s/(eth0\.IP=)([0-9]{1,3}\.){3}[0-9]{1,3}/\1$ipAddress/" filename

Last edited by crts; 10-06-2010 at 02:29 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 replace specyific line with variable zwierzq Linux - Software 4 01-23-2010 10:23 PM
Sed search for variable and delete entire line, but variable contains forward /'s Passions Programming 2 11-10-2008 04:44 PM
how to replace with variable using sed? babag Programming 4 09-17-2008 04:28 PM
Replace variable with user defined variable ce124 Programming 10 04-13-2007 10:29 AM


All times are GMT -5. The time now is 04:28 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration