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 8456501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:33:47+00:00 2026-06-10T12:33:47+00:00

I am using the following Perl oneliner in a bash script to capture multiline

  • 0

I am using the following Perl oneliner in a bash script to capture multiline text between pre tags and add a second iteration of the tag contents wrapped in a different starting and ending string:

new_start_string="NEWSTART"
new_end_string="NEWEND"

perl -i -pe  "BEGIN{undef $/;} s/<pre>(.*?)<\/pre>/<pre>\$1<\/pre>${new_start_string}\$1${new_end_string}/smg" /path/to/file

It works perfectly for the task as specified. I’m aware I’m parsing HTML with regex and that’s not ideal, however the formatting of this text file is a known factor, very simple, under local control and done by local specification so it is a rare case in which parsing would be overkill and I’ve chosen not to do this via parsing.

Using the same oneliner, how can I URL encode the second iteration of the capture value $1 variable? If it’s impossible, is there another approach to get this result that is also relatively simple and readable?

  • 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-10T12:33:48+00:00Added an answer on June 10, 2026 at 12:33 pm

    Because I preferred to use a module in Perl core, I ended using this oneliner using the e modifier in combination with CGI::Util:

    perl -MCGI -i -pe  "BEGIN{undef $/;} s/<pre>(.*?)<\/pre>/'<pre>' . \$1 . '<\/pre>' . '$new_start_string' . CGI::escape(\$1) . '$new_end_string'/esmg" /my/path
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm extracting the content between XML tags using the following: - perl -lne 'BEGIN{undef
I am using following kind of script in my perl script and expecting entry
I'm using the following perl expression to remove tabs from here $text =~ s{(.*?)\t}{$1.('
I am using the following Perl script to do some simple processing: use strict;
I'm trying to clean up form input using the following Perl transliteration: sub ValidateInput
Using following code I try to get updated list of checkbuttons' corresponding text values,
I am using following command for start the production server. nohup ruby script/server webrick
I have the following snippet calling a perl script which writes to STDERR and
I am using following code to create and send email through CGI perl. The
I'm using pQuery (a Perl port of jQuery) to select elements and retrieve text

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.