I have a directory dash7/ which contains multiple text files and I want to remove all lines containing the string D PRINT from all those files.

How can I do that easily from the command-line?

  • 1
    thanks.i have used "find . -type f -print0 | xargs -0 sed -i /KeyWord/d" and its working.thank you. – KISHAN Dec 29 '16 at 10:17
  • 5
    @KISHAN Would you please consider writing an answer to your own question, so that future readers will be able to easily profit from what you found out? Thanks. – Byte Commander Dec 29 '16 at 11:06

You can achieve this rather easily with sed which can happily look into multiple files

sed '/D PRINT/d' dash7/*
  • /D PRINT/ find a line with D PRINT
  • d delete the line
  • dash7/* look in all the files in the directory dash7 (add the path to it, for example ~/dash7 if required)

To actually change the files rather than print the edited text in the terminal, you need to add the -i flag to modify in place

sed -i '/D PRINT/d' dash7/*
  • thanks for suggestion,i hv used " find . -type f -print0 | xargs -0 sed -i /KeyWord/d" and its working.thank you. – KISHAN Dec 30 '16 at 11:26
  • 1
    @KISHAN yes you mentioned that, but I added my answer to help others. You can also help others by posting your solution as an answer to your question instead of a comment :) – Zanna Dec 30 '16 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.