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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:19:48+00:00 2026-06-09T20:19:48+00:00

Using sed, I’m trying to remove everything before a defined pattern and everything after

  • 0

Using sed, I’m trying to remove everything before a defined pattern and everything after a
different one.

head and tail don’t quite cut it because they just remove lines, not characters.

From:

0
0
0A
Z0
)
>

To:

A
Z
  • 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-09T20:19:49+00:00Added an answer on June 9, 2026 at 8:19 pm

    One way:

    sed -ne '
        /A/,/Z/ {
            /A/ s/^[^A]*//;
            /Z/ s/\(Z\).*$/\1/;
            p;
        }
    ' infile
    

    Assuming infile with content:

    0
    0
    01234A56789
    1
    2
    01234Z56789
    )
    >
    

    Result will be:

    A56789
    1
    2
    01234Z
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to insert a line into a file using sed before a pattern and
I'm trying to remove a block inside a pair of matching patterns using sed.
how using sed can I remove all chars in a line after a given
I need a one liner using sed, awk or perl to remove blank lines
I am using sed to replace url's in a file, everything works fine just
I'm trying to replace a text using sed but facing the following error: [root@server3
I am trying to replace properties on a properties file using sed in a
Using sed what is an one liner to print the first n characters ?
I am trying to replace certain functions using SED. Let say I have some
I'm trying to find replace the following <a href=\test\> with <a href=test> using sed.

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.