Delete long lines from a text file (Notepad ++ / EditPlus)

I have a very large text file. Each line in this text file contains a complete sentence. Now I need to delete each line / sentence with more than x characters in it and just save the lines with <= x characters.

Is it possible? Can I do this with Notepad ++ / EditPlus or regular expressions?

Thank you for your help!

+4
source share
3 answers

Using bash:

$ awk '{if (length($0) <= x) print $0; }' myfyle.txt 

Where x is the length. It will print lines less than x .

See the Awk Tutorial and introduction for more awk benefits.

+6
source

This solution is for Notepad ++

Select "Regular Expression" in search mode. Make sure that the ". Matches newline" check box is unchecked .

Find what:. .{x}.+

Replace with: (empty)

If you do not want to leave an empty string after replacement:

Find what:. .{x}.+(\r?\n|\n|$)

Replace x number of your choice.

+7
source

This solution is for Editplus version 3.70.

The next line will delete any line with a length of 201 or more characters if you want to keep lines that are <= 200.

  • Find what: ^. {201,}. * \ n
  • Leave the replacement blank.
  • Check regex

Note the comma after 201.

+1
source

All Articles