Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove long lines from text file (Notepad++/EditPlus)

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!

like image 268
eliah winkler Avatar asked Dec 07 '22 09:12

eliah winkler


2 Answers

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.

like image 77
nhahtdh Avatar answered Dec 16 '22 11:12

nhahtdh


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.

like image 27
Tristian Avatar answered Dec 16 '22 09:12

Tristian