Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextMate find text and then delete entire line?

I'll show you what I want to do using a textmate command or bundle:

Lets say we have the following document:

foo  
diddy
  bah
foo
foobah
diddy

I want to find and delete all the lines matching bah, the desired ouput in this case would be:

foo
diddy
foo
diddy

Thanks!

like image 577
jpemberthy Avatar asked Jan 23 '26 00:01

jpemberthy


1 Answers

With the document you want to filter open,

  • Cmd-F to bring up the Finder window

  • Next, below the two text-entry boxes, click Regular Expression

  • In the Find text box, type in this regexp (without the spaces):

    ^ . * ? bah . * ? $

  • In the Replace text box, do not type in anything--make sure it blank, i.e., no whitespace characters

  • With the cursor at the beginning of the document you want to filter, click one of the buttons at the bottom of the Find Window--e.g., Replace All to remove all of the matching lines in one step, or Replace and Find to step through the lines one at a time

That's it.


Here's a more automated way to do the same thing:

  • from the Menu Bar, select Filter Through Command from the Text pull-down menu

  • enter this into the text box at the top of the small window that appears:

    sed ' / ^ . * bah . * $ / d '

  • select Document as Input and select Replace Document as Output

  • Click Execute

[Note: i inserted spaces between the regexp tokens in both examples because for some reason the asterisks '' were not rendering in HTML page]

like image 78
doug Avatar answered Jan 24 '26 23:01

doug



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!