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

  • Home
  • SEARCH
  • 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 9286515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:26:09+00:00 2026-06-18T19:26:09+00:00

I have two web pages, one page has been created by hand, the other

  • 0

I have two web pages, one page has been created by hand, the other has been published with visual studio 2010 (.aspx). I want to modify the content of these files, replacing a bunch of script tags by a single script tag. To achieve this goal, I simply run some Perl code from a batch file. Here is the Perl code and the HTML before and after substitution :

Perl in a batch :

perl -pi.backup -e "s/<!--\s*<pack>\s*-->.*?<!--\s*<\/pack>\s*-->/<script src=\"pack.js\"><\/script>/s" file.aspx

HTML input :

<!-- <pack> -->
<script src="file1.js" type="text/javascript"></script>
<script src="file2.js" type="text/javascript"></script>
<!-- </pack> -->

HTML output :

<script src="pack.js"></script>

Everything works fine for the hand created file, while the generated file is not updated unless all lines are gathered into one. I guess the issue comes from linebreaks but I can’t figure out why it does work only for the first file since the code is exactly the same.

  • 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-06-18T19:26:10+00:00Added an answer on June 18, 2026 at 7:26 pm

    Your problem is that running Perl with the -p switch causes it to execute the code for each line and print the result. Thus the regex is only seeing one line of the file at a time, and is never able to match the entire pattern.

    You could do something like this:

    perl -i.backup -e "undef $/; $_=<>; s/<!--\s*<pack>\s*-->.*?<!--\s*<\/pack>\s*-->/<script src=\"pack.js\"><\/script>/s; print" file.aspx
    

    It slurps the whole file into $_, then performs your substitution and prints the result to the same file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a web page that has two bars across the top of
I have two web pages that I am trying to send information between. One
I have two web pages which work basically the same, code-wise, but one of
We have some web pages which have two frames, with one frame in the
I have two fields on my web page ie: BookAuthor and BookDescription.On submit,the page
On my web page I have two divs, A and B: The DOM looks
I have the following problem. I got two forms on my web page. On
My web app, up until this point, has been fairly straight forward. I have
I use Visual Studio 2008 primarily for web development, and there's one annoying behaviour
My web application has two search pages - search1.jsf and search2.jsf - which share

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.