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,782
  • 4
  • 27
  • 49

2 Answers2

7

Try this command:

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

Change foobar to what you search for.

kev
  • 146,428
  • 41
  • 264
  • 265
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
  • 190,037
  • 45
  • 260
  • 285