The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help needed sed command. pinga123 Shell Programming and Scripting 2 3 Weeks Ago 08:06 AM
Help needed on sed command 12345 UNIX for Dummies Questions & Answers 2 05-14-2009 09:05 AM
SED command ---------help needed veerapureddy Shell Programming and Scripting 4 03-17-2008 05:12 PM
Help needed for ps command in AIX moe2266 AIX 0 09-30-2005 12:43 PM
help needed for sed command manualvin UNIX for Dummies Questions & Answers 2 06-25-2004 12:41 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 3 Weeks Ago
pinga123 pinga123 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 15
sed command help needed.

Code:
vif = ['bridge=xenbr0,mac=00:16:3E:64:FB:D3,type=ioemu']
I need to replace "00:16:3E:64:FB3" to a new mac address value from below mentioned file.
Code:
[root@OVM-SERVER1 vm_temp]# cat vm.cfg
acpi = 1
apic = 1
builder = 'hvm'
device_model = '/usr/lib/xen/bin/qemu-dm'
disk = ['file:/var/ovs/mount/93B14928C7A6438284753B2F2AB197BB/seed_pool/vm_temp/System.img,hda,w',
'file:/OVS/iso_pool/winxpsp2/WXPVOL_EN.iso,hdc:cdrom,r',
]
kernel = '/usr/lib/xen/boot/hvmloader'
memory = '300'
name = 'vm_temp'
on_crash = 'restart'
on_reboot = 'restart'
pae = 1
serial = 'pty'
timer_mode = '0'
usbdevice = 'tablet'
uuid = '8569c556-fdf9-41f7-93f4-52350560b13c'
vcpus = 1
vif = ['bridge=xenbr0,mac=00:16:3E:64:FB:D3,type=ioemu']
vif_other_config = []
vnc = 1
vncconsole = 1
vnclisten = '0.0.0.0'
vncpasswd = 'oracle'
vncunused = 1
I have created a variable say Var1 and stored value "mac=00:16:3E:64:FB3" in that variable.
I have also created a new Variable say Var2 containing new mac address
say Var2=00:16:3E:64:FB3

Now how do i replace the value "mac=00:16:3E:64:FB3" to "mac=Var2"

I have created following script but it is not working kindly help
Code:
Number3=`grep -n '^vif =' vm.cfg |awk -F":" '{print $1}'`
echo "vif is found at $Number3"
Variable=`grep -n '^vif =' vm.cfg |awk -F"," '{print $2}'`
echo $Variable

sed "s\$Variable\mac=$NewMacAddress\" vm.cfg
  #2 (permalink)  
Old 3 Weeks Ago
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 536
Not sure I understand your problem completely, but if you want to replace that mac address by the value of a shell variable, say ADDR, then:

Code:
$
$ # new address
$ ADDR=99:99:99:99:99:99
$
$ sed "s/^\(vif .*=\)\(.*\)\(,.*\)/\1${ADDR}\3/" vm.cfg
[root@OVM-SERVER1 vm_temp]# cat vm.cfg
acpi = 1
apic = 1
builder = 'hvm'
device_model = '/usr/lib/xen/bin/qemu-dm'
disk = ['file:/var/ovs/mount/93B14928C7A6438284753B2F2AB197BB/seed_pool/vm_temp/System.img,hda,w','file:/OVS/iso_pool/winxpsp2/WXPVOL_EN.iso,hdc:cdrom,r',]
kernel = '/usr/lib/xen/boot/hvmloader'
memory = '300'
name = 'vm_temp'
on_crash = 'restart'
on_reboot = 'restart'
pae = 1
serial = 'pty'
timer_mode = '0'
usbdevice = 'tablet'
uuid = '8569c556-fdf9-41f7-93f4-52350560b13c'
vcpus = 1
vif = ['bridge=xenbr0,mac=99:99:99:99:99:99,type=ioemu']
vif_other_config = []
vnc = 1
vncconsole = 1
vnclisten = '0.0.0.0'
vncpasswd = 'oracle'
vncunused = 1
$
$
HTH
tyler_durden
Bits Awarded / Charged to durden_tyler for this Post
Date User Comment Amount
3 Weeks Ago pinga123 thanks 5
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0