Textmate Regex 101 - clean blank lines

Discussion in 'Mac Programming' started by Caezar, Dec 3, 2009.

  1. Caezar macrumors 6502

    Joined:
    Jun 9, 2004
    Location:
    Between a rock and a hard place
    #1
    I am trying to clean in Textmate some articles I downloaded from Factiva, before I send them to my Sony Reader. I created a command in the Bundle Editor to remove blank lines:

    sed /^$/d

    It works, but now I want to add a new twist and remove blank lines, as well as lines that contain a single space. I tried the following but it does not work:

    sed /^$/d
    sed /^\s$/d

    Any idea?
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
  3. Caezar thread starter macrumors 6502

    Joined:
    Jun 9, 2004
    Location:
    Between a rock and a hard place
    #3
    Unfortunately, neither worked.

    Nothing happened as I launched the first command.

    The second command performed some action, but the result was not as expected...
     
  4. rowsdower macrumors 6502

    Joined:
    Jun 2, 2009
  5. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #5
    Yep, this does work:

    Code:
    sed /^[[:space:]]$/d
    The key is you do need to use double brackets. This isn't really clear from the TextMate manual. This will not work:

    Code:
    sed /^[:space:]$/d
     

Share This Page