sed command help needed.

vif = ['bridge=xenbr0,mac=00:16:3E:64:FB:D3,type=ioemu']

I need to replace "00:16:3E:64:FB:D3" to a new mac address value from below mentioned file.

[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:FB:D3" in that variable.
I have also created a new Variable say Var2 containing new mac address
say Var2=00:16:3E:64:FB:D3

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

I have created following script but it is not working kindly help

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

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:

$
$ # 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