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
sed/shell scripting - add line if needed and not allready there computethis Shell Programming and Scripting 2 4 Weeks Ago 12:44 AM
New Line help needed netfrugal Shell Programming and Scripting 7 10-19-2009 04:19 PM
sed xml file multiple line replacement cbo0485 Shell Programming and Scripting 3 07-15-2009 04:47 PM
Third line occurrence replacement sirokket16 Shell Programming and Scripting 5 07-03-2008 01:04 PM
Help needed in character replacement in Korn Shell stevefox Shell Programming and Scripting 8 03-30-2007 12:59 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 4 Weeks Ago
pinga123 pinga123 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 15
Line Replacement help needed.

I have a file called vm.cfg which looks like follows

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 want to replace a line starting with name = to whatever value i need to assign .For ex.in above file name is assigned 'vm_temp' .I want to create a script which will ask user for a value for name and then assign the same.


I have used following sed command but there is little bug in it .
Please help me to modify it.

Code:
[root@OVM-SERVER1 vm_temp]# sed "s/^name/name = newvalue/g" vm.cfg

Above code produces following output.


Code:
[root@OVM-SERVER1 vm_temp]# sed "s/^name/name = newvalue/g" 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 = newvalue = '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

please help.
  #2 (permalink)  
Old 4 Weeks Ago
pogdorica's Avatar
pogdorica pogdorica is offline
Registered User
  
 

Join Date: Oct 2009
Location: Madrid
Posts: 55
Do you want this?


Code:
[root@OVM-SERVER1 vm_temp]# sed "s/^name.*/name = newvalue/g" vm.cfg

Bits Awarded / Charged to pogdorica for this Post
Date User Comment Amount
4 Weeks Ago pinga123 Thanks 10
  #3 (permalink)  
Old 4 Weeks Ago
pinga123 pinga123 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 15
How would i substitute new value for 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',
]
I want to change the first parameter i.e
file:/var/ovs/mount/93B14928C7A6438284753B2F2AB197BB/seed_pool/vm_temp/System.img
to
some other value.
  #4 (permalink)  
Old 4 Weeks Ago
pogdorica's Avatar
pogdorica pogdorica is offline
Registered User
  
 

Join Date: Oct 2009
Location: Madrid
Posts: 55
Hi.

If that line is all in the same line .......


Code:
newfile="fjsdkfjsl"
sed "s|'file:.*,|'file:$newfile,|"



---------- Post updated at 12:55 PM ---------- Previous update was at 12:33 PM ----------

Hi.

If that line is all in the same line .......


Code:
newfile="fjsdkfjsl"
sed "s|'file:.*,|'file:$newfile,|"

  #5 (permalink)  
Old 4 Weeks Ago
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,098

Code:
echo "Pls input the name"
read name
val=`nawk -F" = " -v name="$name" '$1==name {print $2}' yourfile`
if [ $val = "" ];then
        echo "no such configuration item"
else
        echo $val | sed "s/'//g"
fi

  #6 (permalink)  
Old 4 Weeks Ago
lnviyyapu lnviyyapu is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
line replacement help need

Hi,

Try this ,

===============================
str=`grep name cfg.txt|awk '{print $3}'`
echo "enter the value for "
read repstr
sed "s/$str/\'$repstr\'/" cfg.txt >temp
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 05:49 PM.


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