Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-04-2009, 10:15 PM
|
#1
|
Member
Registered: Sep 2009
Posts: 684
Rep:
|
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.
|
|
|
11-04-2009, 10:21 PM
|
#2
|
Senior Member
Registered: Aug 2006
Posts: 2,697
|
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.
|
|
|
11-04-2009, 11:01 PM
|
#3
|
LQ Newbie
Registered: Oct 2009
Distribution: Mandriva
Posts: 25
Rep:
|
what is the script? code??
Last edited by simer_anand88; 11-04-2009 at 11:02 PM.
|
|
|
11-05-2009, 02:17 AM
|
#4
|
Member
Registered: Sep 2009
Posts: 684
Original Poster
Rep:
|
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
|
|
|
11-05-2009, 02:22 AM
|
#5
|
Senior Member
Registered: Aug 2006
Posts: 2,697
|
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
|
|
|
11-05-2009, 02:43 AM
|
#6
|
Member
Registered: Sep 2009
Posts: 684
Original Poster
Rep:
|
Quote:
Originally Posted by ghostdog74
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.
|
|
|
11-05-2009, 06:54 AM
|
#7
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
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
|
|
|
11-05-2009, 07:06 AM
|
#8
|
Senior Member
Registered: Aug 2006
Posts: 2,697
|
Quote:
Originally Posted by pinga123
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
Last edited by ghostdog74; 11-05-2009 at 07:12 AM.
|
|
|
All times are GMT -5. The time now is 09:01 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|