Line Replacement help needed.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Line Replacement help needed.
# 1  
Old 11-05-2009
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  
Old 11-05-2009
Do you want this?

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

# 3  
Old 11-05-2009
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  
Old 11-05-2009
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  
Old 11-06-2009
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  
Old 11-06-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on find and replacement on specific line and position

I have a file with 100 lines. On 50 th line , from position 5 to rest of the data , I need to change the occurrence of A to B and Occurrence of M to N. Input file : Line1 Line2 Line3 -- -- 12345ABCDEFM --- -- Line 100 Output Line1 Line2 (40 Replies)
Discussion started by: Rajesh_us
40 Replies

2. Shell Programming and Scripting

sed replacement in file when line is in a variable

Hi, I have a file where I want to replace the 15th field separated by comma, only on specific lines matching lots of different conditions. I have managed to read the file line by line, within the loop my line is held in a variable called $line I assume this will be using sed (maybe... (5 Replies)
Discussion started by: jpt123
5 Replies

3. Shell Programming and Scripting

Needed a help in inserting a new line!!!

Hi..wanted a help regarding inserting a newline in an xml file using shell script. i've an xml file which has the following data. 1. <?xml version="1.0" encoding="UTF-8"?> 2. <group> 3. <name>odcm</name> 4. contd.... I need to insert two new lines after line#2, so that the output... (14 Replies)
Discussion started by: arjun_arippa
14 Replies

4. Shell Programming and Scripting

Help needed to split a line

Hi, How can i split a line of string into two lines. I would like to format the below string: Filesystem 1M-blocks Used Available Use% Mounted on /abc/def/xyz 34567 2345 12345 90% /test to Filesystem 1M-blocks Used Available Use% Mounted on /abc/def/xyz 34567 2345 12345 90% /test ... (4 Replies)
Discussion started by: stunnerz_84
4 Replies

5. UNIX for Dummies Questions & Answers

VIM search and replace with line breaks in both the target and replacement text

Hi, Ive spent ages trying to find an explanation for how to do this on the web, but now feel like I'm :wall: I would like to change each occurence (there are many within my script) of the following: to in Vim. I know how to search and replace when it is just single lines... (2 Replies)
Discussion started by: blueade7
2 Replies

6. Shell Programming and Scripting

HELP Need in SED/PERL conditional line replacement

Hi , I need some help on perl/sed conditional replacement The situation is like below . I have a file contents like below . AAA|BBB|CCC|DDD AAA|BCF|CCC|HHH AAA|BVF|JJJ|KKK Here in the above file . I know my second column value (taking "|" as my delimited ) Basically I have to... (3 Replies)
Discussion started by: robin.r888
3 Replies

7. Shell Programming and Scripting

New Line help needed

I am doing a simple SHOW DATABASES query: #!/bin/bash echo `mysql -e "SHOW DATABASES;"` It produces this: Database information_schema mysql test There are 2 things I want to do, but failing at. 1. Exclude the header "Database information_schema" 2. add a new line between each... (7 Replies)
Discussion started by: netfrugal
7 Replies

8. Shell Programming and Scripting

sed xml file multiple line replacement

I have a file called config.xml, it's a simple xml file, and I need use sed/awk to erase some lines. <machine xsi:type="unix-machineType"> <name>server1</name> <node-manager> <name>server1</name> <listen-address>server1</listen-address> </node-manager> ... (3 Replies)
Discussion started by: cbo0485
3 Replies

9. Shell Programming and Scripting

Third line occurrence replacement

You guys are really smart, so I'm hoping someone can help me out with this. I would like to match the third line occurrence of a pattern at the beginning of a line in a file and replace it. I'm ok at using sed but I have no clue about this one. Thanks in advance. (5 Replies)
Discussion started by: sirokket16
5 Replies

10. Shell Programming and Scripting

Help needed in character replacement in Korn Shell

How do I replace a space " " character at a particular position in a line? e.g. I have a file below $ cat i2 111 002 A a 33 0011 B c 2222 003 C a I want all the 1st spaces to be replaced with forward slash "/" and the 3rd spaces to have 5 spaces to get the output below: 111/002... (8 Replies)
Discussion started by: stevefox
8 Replies
Login or Register to Ask a Question