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. |
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.
|
what is the script? code??
|
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 |
there are many ways beside sed to delete a line, here's one other way.
Code:
$ awk '!/^disk/' file > newfile |
Quote:
'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. |
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". http://www.grymoire.com/Unix/Sed.html |
Quote:
Code:
$ awk '/^disk/{f=1}f&&!/\]/{next}f&&/\]/{f=0}f==0' file Code:
$ awk '/disk/,/\]/{next}1' file |
All times are GMT -5. The time now is 08:32 AM. |