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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:52:40+00:00 2026-06-05T17:52:40+00:00

I am attempting to replace multiple lines using sed on a Linux system Here

  • 0

I am attempting to replace multiple lines using sed on a Linux system

Here is my file

<!-- PAGE TAG -->
DATA1
DATA2
DATA3
DATA4
DATA5
DATA6
<div id="DATA"></div>
DATA8
DATA9
<!-- PAGE TAG -->

The attempts I have made and failed!

sed -n '1h;1!H;${;g;s/<!-- PAGE TAG -->.*<!-- PAGE TAG -->//g;p;}' 
sed -n '1!N; s/<!-- PAGE TAG -->.*<!-- PAGE TAG -->// p'
sed -i 's|<!--[^>]*-->[^+]+<!--[^>]*-->||g' 
sed -i 's|/\/\/<!-- PAGE TA -->/,/\/\/<!-- PAGE TA -->||g'

Everything in between <!-- PAGE TAG --> should be replaced.

This question is similar
sed multiline replace

  • 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-05T17:52:43+00:00Added an answer on June 5, 2026 at 5:52 pm

    While @nhahtdh’s answer is the correct one for your original question, this solution is the answer to your comments:

    sed '
      /<!-- PAGE TAG -->/,/<!-- PAGE TAG -->/ {
        1 {
          s/^.*$/Replace Data/
          b
        }
        d
      }
    '
    

    You can read it like so:

    /<!-- PAGE TAG -->/,/<!-- PAGE TAG -->/ -> for the lines between these regexes

    1 { -> for the first matching line

    s/^.*$/Replace Data/ -> search for anything and replace with Replace Data

    b -> branch to end (behaves like break in this instance)

    d -> otherwise, delete the line

    You can make any series of sed commands into one-liners with gnu sed by adding semicolons after each command (but it’s not recommended if you want to be able to read it later on):

    sed '/<!-- PAGE TAG -->/,/<!-- PAGE TAG -->/ { 1 { s/^.*$/Replace Data/; b; }; d; };'
    

    Just as a side note, you should really try to be as specific as possible in your posting. “replaced/removed” means “replaced OR removed”. If you want it replaced, just say replaced. That helps both those of us trying to answer your question and future users who might be experiencing the same issue.

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

Sidebar

Related Questions

I'm attempting to replace a pattern in all my .aspx and .ascx file when
I'm attempting to write a CompiledQuery using Linq-to-Entities that will replace a stored procedure
I'm attempting to write find/replace code for Word documents using Word Automation through Interop.Word
I am attempting to perform some text canonicalization to replace some contractions. Here is
I'm attempting to do a find and replace using regular expressions and grabbing the
I have a file containing perl-style regexs of the form /pattern/replace/ that I'm attempting
I am attempting to replace the Canvas-based rendering system that I already have with
I am attempting to do some find and replace on a java source file.
I am attempting to do a quick replace of the 'innerHTML' of the 'code'
Attempting to find printers / shares in Active Directory using C#. This is my

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.