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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:31:25+00:00 2026-06-11T05:31:25+00:00

I am trying to replace two lines in a file with one new line:

  • 0

I am trying to replace two lines in a file with one new line:

foo1.txt
  aaa   aaa
  bbb   bbb
  ccc   ccc
  ddd   ddd
  bbb   bbb
  ddd   ddd

after the replace the file should look like this

foo1.txt
  aaa   aaa
  eee   eee
  ddd   ddd
  bbb   bbb
  ddd   ddd

Is there a way with sed or some other command make this replace in all files of a folder

I have been trying with sed but without any success: sed 's/bbb\tbbb\nccc\tccc/eee\teee/g' foo*.txt

  • 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-11T05:31:27+00:00Added an answer on June 11, 2026 at 5:31 am

    Even if this question should be already answered in this thread, I didn’t manage to make the “one-line-one-command” solution work.

    This command:

    perl -pe 's/START.*STOP/replace_string/g' file_to_change
    

    seems not to work for me and doesn’t perform a multi-line replace. I had to split it in two different perl scripts, like this:

    perl -pe 's/bbb\tbbb\n.*/placeholderstring/g' foo1.txt | perl -pe 's/placeholderstring  ccc\tccc/eee\teee/g'
    

    Try to see what works best for you.

    EDIT:

    With the new sample text, the only solution that works is the one by William Pursell

    sed '/bbb\tbbb/{ N; s/.*ccc\tccc/  eee\teee/; }' foo1.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying replace two consecutive line breaks with the HTML tag <p/> . So
I am trying to use the sed program to replace two lines of text
I've got two strings that are lines pulled from a file. I'm trying to
I am trying to replace a two letter state abbreviation with text then the
I have been trying to replace a word in a text file with a
I'm trying to read a text file line by line, and add each line
I was trying to remove all comments and empty lines in a file with
I am trying to retrieve data from a file to change it and replace
I am trying to replace a character - say ; - with a new
I'm new with javascript, so i'm trying to use two jQuery plugins, together they

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.