0

i am looking for GREP help. I have an issue where i need to delete every line that contains [DELETELINE].

So that

[DELETELINE] 
TestText
Test [DELETELINE] loremipsum
Example
[DELETELINE] loremipsum
loremipsum [DELETELINE]
[DELETELINE]

becomes

TestText
Example

I only can get parts of it to work. Like delete the line if [DELETELINE] is in the middle or in the beginning or at the end. But i need an expression that catches all cases.

Is that possible?

EDIT:

What i got is this:

^.+\[DELETELINE\].+\r

But this selects only the third line.

0

1 Answer 1

1

I think i found the answer

the following grep works for all cases

^.*\[DELETELINE\].*(\r?|\n?)

^ is beginning of a paragraph \r and \n are different types of linebreaks so everything should be catched.

3
  • 1
    With this query, if your last line must be deleted, it wouldn't be caught because there would be no vertical space at the end of it. Try .*[DELETELINE].*\v? in order to catch it as well. FYI \v means vertical space (it catches both \r and \n) and ? means zero or one time
    – Vinny
    Jan 8, 2018 at 8:39
  • Your recommendation targets every line. Also those two i don't want to touch. But the ? was a good hint. With that my solution works. + 1
    – Pat_Morita
    Jan 8, 2018 at 9:35
  • Oh I see... the anti-slashes before the brackets were deleted in my comment. Just type them back ^^
    – Vinny
    Jan 8, 2018 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.