With a GNU sed:
find . -type f -print0 | xargs -0 sed -i /KeyWord/d
With an OSX sed:
find . -type f -print0 | xargs -0 sed -i '' /KeyWord/d
First command find
finds all the standard files (not directories, or pipes, or etc.), prints them separated by \0
(so filenames can contains spaces, newlines, etc.).
Second command xargs
reads the output of find
, grabs a list based on a separator (\0
because of -0
), invokes sed -i [...]
with added parameters from the list (sed
will be called multiple times if there are a lot of files, as the maximum length of the parameters is limited in each invocation).
The sed
command modifies in-place (-i
).
As to /KeyWord/d
, it'll delete lines containing the regular expression KeyWord
.
You should learn sed
to properly understand the (simple but unusual) syntax, and refer to the appropriate manpages for more information about the tools involved here.
And as I like to promote zsh
, the solution with its extended globs:
sed -i /KeyWord/d **/*(.)
How about just deleting the word "keyword." and not the whole line? – SurenNihalani – 2012-07-11T23:39:43.413
s/KeyWord//g
(substitutesKeyWord
with '' (empty string),g
for all (not only the first on each line). – Pierre Carrier – 2012-07-15T17:23:45.483