7

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?

2
  • 1
    thanks.i have used "find . -type f -print0 | xargs -0 sed -i /KeyWord/d" and its working.thank you.
    – KISHAN
    Dec 29, 2016 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, 2016 at 11:06

1 Answer 1

9

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/*
2
  • thanks for suggestion,i hv used " find . -type f -print0 | xargs -0 sed -i /KeyWord/d" and its working.thank you.
    – KISHAN
    Dec 30, 2016 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, 2016 at 12:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .