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 8282333

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:20:19+00:00 2026-06-08T10:20:19+00:00

I have the following code for finding a string in a file then delete

  • 0

I have the following code for finding a string in a file then delete the line which contains that string.

echo `sed  /$string/d  file.txt` > file.txt

the problem is that if initially file.txt contains:

a
b
c

after deleting “a” (string=a) file.txt will become

b c

instead of

b
c

can any one help me?

  • 0 0 Answers
  • 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-08T10:20:22+00:00Added an answer on June 8, 2026 at 10:20 am

    This is because of the backticks. Do this instead:

    sed -i /$string/d  file.txt
    

    Note, if you want to do this in-place, you need to use -i to sed as > will destroy the file before sed can read it.

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

Sidebar

Related Questions

hello i have following code and it works fine for finding and replacing string...
I have the following code. It's not finding my resource: string filename = Resources/Functions.plist;
I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using
I have following code that I am compiling in a .NET 4.0 project namespace
I have the following jQuery code for finding the sum of all table rows,
I have the following code: public class DeserializeAndCompare { public static List<string> IntoXML() {
I have the following code that loops trough a range and formats some PivotItems
I have the following code in my app that will show a list of
I have the following bit of code that reads data from the an Oracle
I have the following code that defines a getParts method to find a given

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.