Delete all lines in a .txt with a certain length

2013-09-30
2013-11-10
  • mangooogames

    mangooogames - 2013-09-30

    Hello,
    I try to delete all lines with a length of 4 or less characters from a file that has a line per word (it is a very simple dictionary).
    Deleting every short line in this gigantic file would be several hours of work.
    Is there a way to automatically delete all words/lines including the \n automatically?
    Greetings,
    mangooogames

     
  • mangooogames

    mangooogames - 2013-09-30

    Okay, I found it out myself:
    I created a regular expression (regex) and used "Replace all" with an empty replacement.
    This was the expression:

    \b[A-Za-z0-9]{1,4}\b\r\n

    Greetings,
    mangooogames

     
    Last edit: mangooogames 2013-09-30
  • THEVENOT Guy

    THEVENOT Guy - 2013-10-04

    Hello mangooogames,

    Fine ! You were able to find out this regex by yourself. It's the best way to progress on making powerful regular expressions :-)

    Just 3 hints :

    • If you don't mind to add the underscore character (_) to the allowed characters, use the \w form which is identical to the class character [A-Za-z0-9_]

    • Instead of the couple \r\n, you would better use the \R form which represents \r\n in a Windows file, \n in an Unix file or \r in an old Mac file !

    • You don't need to enclose words with the assertion \b ( word boundary ). Just, add the assertion ^ ( anchor ), at beginning of the regex, which stands for the very beginning of each line.

    So, the final regular expression, to suit your needs, can be shortened in :

    ^\w{1,4}\R

    Enjoy our loved and powerful editor :)

    Best Regards,

    guy038

    P.S. :

    You will find good documentation, about the new Perl Common Regular Expressions (PCRE), used by N++, since the 6.0 version, at the TWO addresses below :

    http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

    http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

    The FIRST link concerns the syntax of regular expressions in SEARCH

    The SECOND link concerns the syntax of regular expressions in REPLACEMENT

     
    Last edit: THEVENOT Guy 2013-10-04
  • mangooogames

    mangooogames - 2013-11-10

    Thank you for your advice!
    The topic is no longer of relevance for me, since I only needed the regex once, but some additional knowledge can't be wrong.

    Greetings,
    mangooogames