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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:19:28+00:00 2026-05-11T02:19:28+00:00

I have a bat file that I should use to delete a part of

  • 0

I have a bat file that I should use to delete a part of one file and save into another one. I need to delete all the symbols between text ‘[aaa bbb]’ and ‘[ccc ddd]’. That is if I have the text:

[aaa bbb] 1 2 3 [ccc ddd] 

I should have as output:

[aaa bbb] [ccc ddd] 

Thank you

EDIT: I would like to clarify the question. I should delete all the symbols between marker1 and marker2. Marker1 and marker2 are just some words or parts of text but not obligatory lines. For example I would have:

[aaa bbb] [ccc] 1 2 3 4 5 [www yyy] 

If I want to delete the text between [aaa bbb] and [www yyy] I should have as output:

[aaa bbb]  [www yyy] 
  • 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. 2026-05-11T02:19:29+00:00Added an answer on May 11, 2026 at 2:19 am

    Take a look at the section ‘Delete between marker 1 and marker2’ on this sed hints page

    Applying it on your example. clean.sed:

    /^\[aaa bbb\]$/,/^\[ccc ddd\]$/{  /^\[aaa bbb\]$/!{    /^\[ccc ddd\]$/!d  } } 

    Run using:

    sed -f clean.sed inputfile.txt 

    To edit the input file ‘in place’, use the -i option to sed:

    sed -i.bak -f clean.sed datafile.txt 

    A backup copy of the file with the name ‘datafile.txt.bak’ is saved before editing the original.

    EDIT: Since the assumption that the markers where always on a line of their own was wrong, heres a script that can handle markers in the middle of a line:

    /\[aaa bbb\]/,/\[ccc ddd\]/{   s/\[aaa bbb\].*/[aaa bbb]/   s/.*\[ccc ddd\]/[ccc ddd]/   /\[aaa bbb\]$/!{     /^\[ccc ddd\]/!d   } } 

    For this input:

    foo[aaa bbb]1 2 3 4 5[ccc ddd]bar foo [aaa bbb] 1 2 3 [ccc ddd] bar 

    It produces:

    foo[aaa bbb] [ccc ddd]bar foo [aaa bbb] [ccc ddd] bar 

    Note! It can’t handle files where the markers can appear on the same line.

    EDIT again: If the input format for marker 1 is such that you can always count on it being on a line of its own you can simplify the script some:

    /^\[aaa bbb\]$/,/\[ccc ddd\]/{   s/.*\[ccc ddd\]/[ccc ddd]/   /^\[aaa bbb\]$/!{     /^\[ccc ddd\]/!d   } } 

    (Anchoring marker 1 at the beginning and end of a line and skipping the trimming of the marker 1 line.)

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

Sidebar

Related Questions

No related questions found

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.