0

How can I do a string match against, for example:

<meta name="keywords" content="

Then delete that whole line every time a match is found?

I'm looking to do this for all files in the current directory and below.

I'm also new to sed.

Barney
  • 1,820
  • 5
  • 29
  • 50

2 Answers2

7

Try this command:

find . -type f -exec sed -i '/foobar/d' {} \;

Change foobar to what you search for.

kev
  • 155,172
  • 47
  • 273
  • 272
2

In answer to the question: "How do I do x to all files recursively?", the answer is to use find. To use sed to delete a line, you can either use the non-portable -i, or simply write a script to redirect the stream. For example:

find . -exec sh -c 'f=/tmp/t.$$; 
    sed "/<meta name=\"keywords\" content=\"/d" $0 > $f; mv $f $0' {} \;
William Pursell
  • 204,365
  • 48
  • 270
  • 300