LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Delete a line from a file (https://www.linuxquestions.org/questions/linux-newbie-8/delete-a-line-from-a-file-766956/)

pinga123 11-04-2009 10:15 PM

Delete a line from a file
 
Hi guys,

How do i write a script which will delete a perticular line from a file starting with "shell" word.

ghostdog74 11-04-2009 10:21 PM

what have you learnt till now since you started 70 posts ago? Put in some effort and show us some code. I ask because this is a very simple task.

simer_anand88 11-04-2009 11:01 PM

what is the script? code??

pinga123 11-05-2009 02:17 AM

I m explaining in detail.

Below is the content of my file called vm.cfg.
I need to delete a line starting from disk word so when i write
sed "/^disk/d" vm.cfg
It only delete the line
disk = ['file:/var/ovs/mount/93B14928C7A6438284753B2F2AB197BB/seed_pool/vm_temp
and not
/System.img,hda,w',
'file:/OVS/iso_pool/winxpsp2/WXPVOL_EN.iso,hdc:cdrom,r',
]
How can i establish this.
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


ghostdog74 11-05-2009 02:22 AM

there are many ways beside sed to delete a line, here's one other way.
Code:

$ awk '!/^disk/' file  > newfile
I suggest you start learning awk from now on. see my sig

pinga123 11-05-2009 02:43 AM

Quote:

Originally Posted by ghostdog74 (Post 3745375)
there are many ways beside sed to delete a line, here's one other way.
Code:

$ awk '!/^disk/' file  > newfile
I suggest you start learning awk from now on. see my sig

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',
]
Thanks for your help but.
I want to write a program which will delete above mentioned set of lines.

pixellany 11-05-2009 06:54 AM

There will be no SED vs. AWK wars.......;)

Have you read a tutorial on SED? I ask this because you used an address/action statement earlier---what you need is an address range, like so:

Code:

sed '/start/,/finish/ d'  ##deletes all lines, beginning with on containing "start", and ending on one containing "finish".

sed '/start/,+3 d'  ##as above, but deletes 3 lines after the first address

Best SED tutorial here:
http://www.grymoire.com/Unix/Sed.html

ghostdog74 11-05-2009 07:06 AM

Quote:

Originally Posted by pinga123 (Post 3745385)
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',
]
Thanks for your help but.
I want to write a program which will delete above mentioned set of lines.

Code:

$ awk '/^disk/{f=1}f&&!/\]/{next}f&&/\]/{f=0}f==0' file
or
Code:

$ awk '/disk/,/\]/{next}1' file


All times are GMT -5. The time now is 08:32 AM.