views:

30

answers:

1

Hi folks, 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!

+1  A: 

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]

doug
Hey thanks for your answer! everything is working almost right, maybe I'm missing something, but after following your instructions the output I'm getting is this: http://gist.github.com/500613 instead of http://gist.github.com/500616.
jpemberthy
i coudldn't reproduce your output; anyway, i edited my Answer above to include an alternative using "Filter Through Command" (and which is actually easier to use).
doug
The filter worked! thanks!
jpemberthy