Page 1 of 1

How do i erase all line if i find certain text?

Posted: Mon Jun 28, 2010 10:05 pm
by Gastons
I find word 'water' in 55 files.
How do I erase all lines which contain word 'water' in all 55 files?

Posted: Wed Jun 30, 2010 6:46 am
by SpiroC
This should work, but you should test it first (make copies of files, check results with a compare utility):

Regular Expression:
Reg Ex: .*water.*[\r\n]+

Replace:

Note: leave replace empty.

Posted: Wed Jun 30, 2010 9:39 am
by DV
That'll do it - just be sure that 'Dot Matches Newline' is not ticked.
You can try it out using the regex tester in textcrawler.

Posted: Wed Jun 30, 2010 8:56 pm
by Fool4UAnyway
Wouldn't it be safer to put it this way? :

^.*water.*$

Posted: Thu Jul 01, 2010 9:25 pm
by Fool4UAnyway
OK, it occurred to me what the difference is between the two proposed regular expressions.

^.*water.*$

This one will only match the _contents_ of lines containing the word water and replacing those with nothing will _clear_ those lines, not delete them. You will be left with _empty_ lines where a match was found.

.*water.*[\r\n]+

This one, on the other hand may also include empty lines _after_ each line that contains the word water, because "any number of consecutive newline characters, with at least one" will be accepted.

I don't know how to include only one single newline character that could be _either_ \r _or_ \n _or_ \r\n.

Posted: Thu Jul 01, 2010 9:27 pm
by Fool4UAnyway
> I don't know how to include only one single newline
> character that could be _either_ \r _or_ \n _or_ \r\n.

Just reading what I just wrote made me realise this is just how you should build the regular expression:

(\r|\n|\r\n)

So this one would be like perfect:

.*water.*(\r|\n|\r\n)