Deleting lines that are longer than specified value

Help with writing and playing macros

Deleting lines that are longer than specified value

Postby greg123 » Wed Oct 06, 2010 12:14 pm

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
greg123
Newbie
 
Posts: 7
Joined: Mon Jun 21, 2010 5:48 am

Re: Deleting lines that are longer than specified value

Postby Mofi » Thu Oct 07, 2010 12:29 am

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Deleting lines that are longer than specified value

Postby greg123 » Thu Oct 07, 2010 1:07 pm

It's very fast solution. Thanks for explanation.
Greg
greg123
Newbie
 
Posts: 7
Joined: Mon Jun 21, 2010 5:48 am


Return to Macros