Nips
Nips

Reputation: 13890

How to remove specific lines from all files?

I want to delete all lines begin with 'sometext' from many files:

find . -name "*.php"|xargs -I {} sed -e '/^sometext/d' {}

But this put me output to console. How to modify this files directly?

Upvotes: 1

Views: 71

Answers (3)

Michael
Michael

Reputation: 58507

You can accomplish this with exec:

find . -name "*.php" -exec sed -i '/^sometext/d' {} \;

Upvotes: 0

Bohemian
Bohemian

Reputation: 425428

Tell sed to modify the files "in place":

find . -name "*.php" | xargs sed -i '' -e '/^sometext/d'

Note that the blank '' after -i is required, otherwise a new copy with a default suffix will be created.

Also note the pruning if your unnecessary -I in xaegs

Upvotes: 1

Guru
Guru

Reputation: 17054

Use -i option of sed:

 sed -i -e '/^sometext/d' file

Upvotes: 1

Related Questions