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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:22:46+00:00 2026-06-17T11:22:46+00:00

This question refers to How to replace text using greedy approach in sed? I

  • 0

This question refers to

How to replace text using greedy approach in sed?

I have to match multiline data in file and need to replace them with some other text using perl.

cat file

 <strong>ABC
       </strong>

perl script: code.pl

 #!/bin/perl
 open(fh, $ARGV[0]) or die "could not open file\n";
 while($input = <fh>)
 {
      if($input =~/&lt;strong&gt;(.*?)\n(\s)*&lt;\/strong&gt;/)
      {
          print($1,"\n");
      }
 }
 close(fh);

perl code.pl file

Output: No output

How to solve above pblm.

Regards

  • 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-17T11:22:47+00:00Added an answer on June 17, 2026 at 11:22 am
    use File::Slurp qw( read_file );
    
    my $string = read_file( $ARGV[0] );
    
    $string =~ s/\&lt;strong&gt;(.*?)&lt;\/strong&gt;/<b>${1}<\/b>/gs;
    
    print $string;
    

    This example uses the File::Slurp module to read in the entire file at once.

    It then uses a regex with the g and s modifiers. The s allows .*? to match newline characters. The g makes the search global. Global meaning it will find all matches in the given string. Without the g only the first instance would be replaced. If you want your search to be case insensitive, you can use the i regex modifier.

    The ${1} is a back-reference to the match in parentheses.

    This example produces:

    <b>ABC
         </b>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Textbox refers to <input type=text> in this question. For each textbox with a given
This question refers to the Delegation design pattern found here . I have a
This question refers to performance, not to file size. I know there are min
Note: This question refers to a Rails project with Sass & Compass. Using the
I understand that this question refers to the trivial so I have two tables(one
THIS QUESTION REFERS TO RESTKIT 0.9.x. IF YOU ARE NEW TO RESTKIT CONSIDER USING
Note, this is not a duplicate of .prop() vs .attr() ; that question refers
Note: In this question I'm using the term autocomplete (or iterative search) to refer
This question is related to another question I wrote: Trouble using DOTNET from PHP.
This question refers to the question Show/hide fields depending on select value <select id=viewSelector>

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.