Deleting lines that are longer than specified value

Deleting lines that are longer than specified value

7
NewbieNewbie
7

    Oct 06, 2010#1

    Hi,
    1. I need to delete lines that are longer than specified line length (e.g. 180 chars). My macro works, but it's extremely slow.
    2. It wolud be nice not to have to specify number of loops to run (50000 in this example).
    Please help.

    Here is my macro:

    InsertMode
    ColumnModeOff
    HexOff
    Loop 50000
    Key END
    IfColNumGt 180
    DeleteLine
    Else
    Key DOWN ARROW
    EndIf
    EndLoop

    6,605548
    Grand MasterGrand Master
    6,605548

      Oct 07, 2010#2

      That can be done with a simple Perl regular expression replace.

      InsertMode
      ColumnModeOff
      HexOff
      Bottom
      IfColNumGt 1
      InsertLine
      IfColNumGt 1
      DeleteToStartofLine
      EndIf
      EndIf

      Top
      PerlReOn
      Find RegExp "^.{181,}\r*\n"
      Replace All ""

      The green part makes sure that last line of file has a line termination.

      ^ ... start of line.

      . ... any character except new line characters like carriage return and line-feed.

      {181,} ... the preceding expression (any character) at least 181 times.

      \r*\n ... a carriage return 0 or more times followed by a line-feed. If your files are DOS files you can remove the * from this part of the expression.
      Best regards from an UC/UE/UES for Windows user from Austria

      7
      NewbieNewbie
      7

        Oct 07, 2010#3

        It's very fast solution. Thanks for explanation.
        Greg