2

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!

jpemberthy
  • 7,473
  • 8
  • 44
  • 52

2 Answers2

10

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
  • 69,080
  • 24
  • 165
  • 199
  • 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 Jul 30 '10 at 14:37
  • 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 Jul 30 '10 at 21:48
3

Building on top of @doug's answer Since the user wants to delete the line after the match, the solution using Regex is

^ . * ? bah . * ? $\n

Matching the \n at the end will remove the line