4

I have a very big text file. Every line in this textfile has a complete sentence in it. Now I have to remove every line/sentence with more than x characters in it and just keep the lines with <=x characters.

Is this even possible? Can i do this with Notepad++/EditPlus or Regular Expressions?

Thank you for your help!

eliah winkler
  • 73
  • 1
  • 3

3 Answers3

8

This is solution for Notepad++

Choose "Regular expression" in Search Mode. Make sure ". matches newline" checkbox is unchecked.

Find what: .{x}.+

Replace with: (empty)

If you don't want to leave an empty line after replacement:

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

Replace x with number of your choice.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
6

Using bash:

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

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

See Awk Tutorial and Introduction for more awk goodies.

Tristian
  • 3,406
  • 6
  • 29
  • 47
  • This does not seem to work, yet the up-votes suggest that it should. I created a file with a very large line. However, no matter what the value of x that I put the file will not change. Is there something missing? – Kvothe May 31 '21 at 17:43
1

This is the solution for Editplus version 3.70.

The following will delete any line that is 201 characters or more if you want to keep lines that are <= 200.

  • Find what: ^.{201,}.*\n
  • Leave replace with blank
  • Check regular expression

Note the comma after the 201.

Tai Paul
  • 900
  • 10
  • 19