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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:46:44+00:00 2026-06-15T22:46:44+00:00

The below command will find all occurances of a string and delete the contents

  • 0

The below command will find all occurances of a string and delete the contents of the files where this string is found.

find / -maxdepth 1 -xdev -type f -exec grep -i "stringtofind" -l {} \; -exec sed -i '/./d' {} \;

I have tried modifying it to just delete the lines where the string is found but can’t get it to work.

E.g test file:

blah blah blah
blah blah blah teststring
teststringblah blah blah
blah blah blah

It would delete lines 2 and 3 and leave the file as without gaps between lines:

blah blah blah
blah blah blah
  • 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-15T22:46:45+00:00Added an answer on June 15, 2026 at 10:46 pm

    No need for grep here sed -i '/teststring/Id' file deletes all lines in file that contain teststring (case-insensitive) so just combined that with find:

    find . -maxdepth 1 -xdev -type f -exec sed -i '/teststring/Id' {} \;
    

    sed demo:

    $ cat file
    blah blah blah
    blah blah blah teststring
    teststringblah blah blah
    blah blah blah
    
    $ sed '/teststring/Id' file
    blah blah blah
    blah blah blah
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to update all records in my database(mongodb),I tried to use command below
I've looked all over for an answer to this, and I can't find any
I have the below command line arguments set for the program. argument proc is
When i give the below command , it interacts with my database and give
I have created one table using the below command: create table Table1( Id int
I execute the command below to revoke a user's permissions to execute a particular
When i run the command below: 127.0.0.1:8080/solr/suggest?spellcheck.build=true I got an exception as below, anyone
i have a column family use counter as create table command below: (KEY i
I tried command like below. But can't see server time. psexec \\SERVER_NAME -i -u
I have the code below: using (SqlCommand command = new SqlCommand()) { command.CommandType =

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.