Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7651087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:25:09+00:00 2026-05-31T11:25:09+00:00

For a pattern looking like this: <VirtualHost 127.0.0.1:81> Directive1 Directive2 </VirtualHost> I want to

  • 0

For a pattern looking like this:

<VirtualHost 127.0.0.1:81>
  Directive1
  Directive2
</VirtualHost>

I want to insert a new line with the string Directive3 before </VirtualHost>. Note that they can be several <VirtualHost/> declarations in the file but that they all have unique IP:PORT pair. This is what I have so far:

perl -p -i -e 's/(<VirtualHost 127\.0\.1\.1:81>[^(<\/VirtualHost>)+])(<\/VirtualHost>)/$1\n\tDirective3\n$2/ims' $file

Which broken down gives:

  • has <VirtualHost 127.0.0.1:81>
  • followed by
  • has everything except </VirtualHost>
  • followed by
  • </VirtualHost>

But this does not match anything :(…

Any idead?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:25:10+00:00Added an answer on May 31, 2026 at 11:25 am

    perl -p reads the file one line at the time. You can use -0777 to make it read the whole file.

    Or you could use something like:

    perl -pE '(/<VirtualHost +127\.0\.0\.1:81>/ .. /<\/VirtualHost>/) =~ /E/ and say "\tDirective3"'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a list looking like this: List=[alpha(1,2),beta(3,4),gamma(4,1)] Ok, so I want
I'm looking for a following pattern: I have several methods like this: 1. private
I have a string like this: N:string of unknown length\r\n I want string of
I Looking for a method that convert time string into Calendar look like this:
I have a name pattern looking like this: F. O. O. Bar F. Oobar
So I'm looking for a pattern like this: size='0x0' In a log file, but
I have a .txt file looking like this: 1 Some string Some other string
I've been looking around for a good pattern to implement a insert then cancel
Say I have some data like this: number_stream = [0,0,0,7,8,0,0,2,5,6,10,11,10,13,5,0,1,0,...] I want to process
I'm looking for help identifying this design pattern and learning the typical vocabulary it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.