Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete a line that contains a word in all text files of a folder? [closed]

Tags:

linux

bash

So, in linux, I have a folder with lots of big text files.

I want to delete all the lines of these files that contain a specific keyword. Is there any easy way to do that across all files?

like image 421
AndroidSec Avatar asked Oct 20 '25 14:10

AndroidSec


2 Answers

There already many similar answers. I'd like to add that if you want to match this is a line containing a keyword but not this is a line containing someoneelseskeyword, then you had better added brackets around the word:

sed -i '/\<keyword\>/d' *.txt
like image 118
Jo So Avatar answered Oct 22 '25 04:10

Jo So


I cannot test this right now, but it should get you started

find /path/to/folder -type f -exec sed -i '/foo/d' {} ';'
  • find files in the directory /path/to/folder
  • find lines in these files containing foo
  • delete those lines from those files
like image 21
Zombo Avatar answered Oct 22 '25 02:10

Zombo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!