deleting lines above and below a word!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting deleting lines above and below a word!
# 1  
Old 03-25-2011
deleting lines above and below a word!

i jst want to delete a host entry from httpd.conf
for eg:


i have entries such as:

Code:
<VirtualHost 192.168.1.157:80>
DocumentRoot /home/karthik
ServerName kar
</VirtualHost>
<VirtualHost 192.168.1.157:80>
DocumentRoot /home/karthik1
ServerName www
</VirtualHost>
<VirtualHost 192.168.1.157:80>
        DocumentRoot /home/lalz
        ServerName lal.com
</VirtualHost>

i want to delete the entry containing the domain name lal.com
ie..the output should be:
Code:
<VirtualHost 192.168.1.157:80>
DocumentRoot /home/karthik
ServerName karthiks
</VirtualHost>
<VirtualHost 192.168.1.157:80>
DocumentRoot /home/karthik1
ServerName karthik1
</VirtualHost>



the entry for lal.com should be deleted!!
anyone..plz help me out!!
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 03-25-2011 at 08:24 AM.. Reason: code tags, please!
# 2  
Old 03-25-2011
Can you elaborate more the subject line of thread and what you are expecting is confusing, you want to delete lal.com but as per the output file its deleting some other text too.
# 3  
Old 03-25-2011
Code:
awk '/lal.com/ {p="";getline;next} {p=p"\n"$0} NR%4==0{print p;next}' input_file| sed '/^$/d'

# 4  
Old 03-25-2011
Code:
awk 'BEGIN{RS="</VirtualHost>"; ORS=""} /lal/{next}1' httpd.conf | awk '/^$/{print "</VirtualHost>";next}1'

or
Code:
awk 'BEGIN{RS="</VirtualHost>"; ORS=""} /lal/{next}1' httpd.conf | sed 's/^$/<\/VirtualHost>/'

# 5  
Old 03-26-2011
thank you every one...
the code is working
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed for deleting the first word of each line?

sed /'1-2'/&^/ filename suppose there is a file containing three lines , how do we do delete the word from each line? hyter efr frf rerfer efe ewd cdcf evrfgf erfv the output has to look like frf ewd erfv (2 Replies)
Discussion started by: Rajeev Nukala
2 Replies

2. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

3. Shell Programming and Scripting

Deleting lines in a fixed length file where there is a word at specific location

I have a big file having 100 K lines. I have to read each line and see at 356 character position whethere there is a word "W" in it. If it is their then don't delete the line otherwise delete it. There are two lines as one Header and one trailer which should remain same. Can somebody... (5 Replies)
Discussion started by: mohit kanoongo
5 Replies

4. Shell Programming and Scripting

Deleting rows starting with a character and word

Hi, I have multiple files of same format and I want to delete the lines starting with # and The from all of them I am using egrep -v '^(#|$)' for # but unable to do for both # and The Please guide Thanks (12 Replies)
Discussion started by: bioinfo
12 Replies

5. Shell Programming and Scripting

Deleting a word from a string

Hello All, I have a string like below - /LDCA20/rel/prod/libina.a I want to delete "libina.a" which is at the end.How can I do this ?? Thanks in advance Regards, Anand (10 Replies)
Discussion started by: anand.shah
10 Replies

6. Shell Programming and Scripting

Search the word to be deleted and delete lines above this word starting from P1 to P3

Hi, I have to search a word in a text file and then I have to delete lines above from the word searched . For eg suppose the file is like this: Records P1 10,23423432 ,77:1 ,234:2 P2 10,9089004 ,77:1 ,234:2 ,87:123 ,9898:2 P3 456456 P1 :123,456456546 P2 abc:324234 (2 Replies)
Discussion started by: vsachan
2 Replies

7. Shell Programming and Scripting

sed - deleting each line up to a word

Hi there, I'd like to delete the beginning of a line up until it finds a certain word or character string: in this case, I'd like to delete each line up to the word "mounting". Thanks ;) Susan (12 Replies)
Discussion started by: kitykity
12 Replies

8. UNIX for Dummies Questions & Answers

deleting word from this point to end of file in VI

Hi All i need to delete a recurring word from point "n" till end of the file. there are other words in this file so i cannot use `dG`, can anyone help me out? Kind regards Brian (4 Replies)
Discussion started by: brian112
4 Replies

9. Shell Programming and Scripting

Word count of lines ending with certain word

Hi all, I am trying to write a command that can help me count the number of lines in the /etc/passwd file ending in bash. I have read through other threads but am yet to find one indicating how to locate a specifc word at the end of a line. I know i will need to use the wc command but when i... (8 Replies)
Discussion started by: warlock129
8 Replies

10. Shell Programming and Scripting

deleting last characters of a word

Hi All is there a way to delete last n characters from a word like say i have employee_new i want to delete _new. and just get only employee I want this in AIX Shell scripting Thanks (3 Replies)
Discussion started by: rajaryan4545
3 Replies
Login or Register to Ask a Question