LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-19-2006, 02:17 PM   #1
digitalbrutus
LQ Newbie
 
Registered: Mar 2004
Posts: 25

Rep: Reputation: 15
Question pattern matching problem in sed


I need to write a script to delete a <VirtualHost>...</VirtualHost> entry of a particular domain from httpd.conf using sed or awq or anything.

I tried to do it with sed but the pattern was too complecated for me to understand and use. How do we match multiple line and remove those lines from a file using sed/awk. Plese help?
 
Old 08-19-2006, 02:22 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

Is this what you want:

sed -n '/<VirtualHost>/,/<\/VirtualHost>/!p' <infile>

Hope this helps.
 
Old 08-19-2006, 09:37 PM   #3
kladizkov
LQ Newbie
 
Registered: Jul 2005
Posts: 9

Rep: Reputation: 0
sed -n '/<VirtualHost>/,/<\/VirtualHost>/!p' <infile>[/b]

That doesnt work. Actually iam looking for a search and replace command in sed, that is i can search for <VirtualHost>...</VirtualHost> and replace it with a space or null character
 
Old 08-20-2006, 12:11 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,965
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
Code:
sed '/^<[Vv]irtual[Hh]ost.*>/, ^<\/[Vv]irtual[Hh]ost>/ d' httpd.conf
actually works

Just make sure you add some sensible stuff where it's red
so you don't wipe ALL of it. Inserting null or the likes
doesn't make sense, and empty virtual host definition gains
you nothing. If this is not what you want you could try
and just comment things out.
Code:
sed '/^<[Vv]irtual[Hh]ost.*>/, /^<\/[Vv]irtual[Hh]ost>/ s/^/# /' httpd.conf
Cheers,
Tink
 
Old 08-20-2006, 04:40 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

@kladizkov: My solution doesn't work for you, but you are not the OP. Yours is a different question altogether.

To avoid confusion please open a new thread if the question is different form the original one.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script pattern matching thedude2010 Programming 9 06-02-2006 02:39 AM
Perl pattern matching in VB rigel_kent Programming 1 05-30-2006 11:00 AM
Perl Pattern Matching Question pete1234 Programming 2 08-27-2005 10:26 AM
Pattern Matching Help in Bash script cmfarley19 Programming 1 04-07-2004 09:22 AM
pattern matching in perl ludeKing Programming 9 04-02-2004 09:53 AM


All times are GMT -5. The time now is 06:34 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration