Clean Up Files - all tabs to spaces, trim trailing spaces, remove consecutive blank lines

Help with writing and playing macros

Clean Up Files - all tabs to spaces, trim trailing spaces, remove consecutive blank lines

Postby LBurr » Thu Jun 09, 2011 1:34 pm

Good afternoon. I've gotten in hundreds of files that all need the following done on in this order:

Change All Tabs to Spaces
Trim Trailing Spaces
Remove Consecutive Blank Lines (two or more) and change to just one

For example - I have


djsdkjsdjjkejf TAB TAB TAB TAB jkdjkfskjkekrkej fjksdfksdjfjkejkwjekfjksdf SPACE SPACE SPACE PARAGRAPH MARK
ddjjfll kkellsll jjjekkkk TAB TAB dkdklwlekdkkfskdlkdjsklkd TAB TAB TAB TAB dskfdkjdjfdkkwekrekf SPACE PARAGRAPH MARK
PARAGRAPH MARK
PARAGRAPH MARK
PARAGRAPH MARK
PARAGRAPH MARK
PARAGRAPH MARK
dsfkdkkdskfkdekkkkkk dkdkskdfjdk TAB TAB TAB TAB jdfkskdfkdk SPACE SPACE SPACE PARAGRAPH MARK
PARAGRAPH MARK
dkdsdjfkdksjkfjkejkwekkdsjfjkd TAB TAB TAB djfksdjkfdks SPACE SPACE SPACE SPACE PARAGRAPH MARK


I need:

djsdkjsdjjkejf SPACE SPACE SPACE SPACE jkdjkfskjkekrkej fjksdfksdjfjkejkwjekfjksdfPARAGRAPH MARK
ddjjfll kkellsll jjjekkkk SPACE SPACE dkdklwlekdkkfskdlkdjsklkd SPACE SPACE SPACE SPACE dskfdkjdjfdkkwekrekfPARAGRAPH MARK
PARAGRAPH MARK
dsfkdkkdskfkdekkkkkk dkdkskdfjdk SPACE SPACE SPACE SPACE jdfkskdfkdkPARAGRAPH MARK
PARAGRAPH MARK
dkdsdjfkdksjkfjkejkwekkdsjfjkd SPACE SPACE SPACE djfksdjkfdksPARAGRAPH MARK

The simple It's mainly the removing consecutive blank lines that I am having the trouble with. I've read the FAQs and the in the PowerTips and researched as much as I can but all of them seem to just remove ALL blank lines (and even then states you have to keep running it over and over to do multiple lines.

I was thinking there must be a way to use the
find ^p$
to be two or more and replace with ^p

Any assistance would be appreciated.

L
User avatar
LBurr
Newbie
 
Posts: 4
Joined: Wed Jul 25, 2007 11:00 pm

Re: Clean Up Files - all tabs to spaces, trim trailing spaces, remove consecutive blank lines

Postby Mofi » Fri Jun 10, 2011 12:40 am

Multiple blank lines (with no spaces/tabs) can be deleted for example with using the UltraEdit regular expression searching for ^p^p[^p]+ and using ^p^p as replace string. That expression is for DOS terminated lines. With Unix or Perl engine the search string is \r\n\r\n[\r\n]+ and the replace string \r\n\r\n. But those expressions do not remove all blank lines at top of the file. The macro could be:

Code: Select all
InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
TrimTrailingSpaces
TabsToSpaces
Find RegExp "  +"
Replace All " "
Find RegExp "^p^p[^p]+"
Replace All "^p^p"
Key END
IfColNum 1
DeleteLine
Key END
IfColNum 1
DeleteLine
EndIf
EndIf
Top

The code below second Find/Replace All is for deleting 1 or 2 blank lines at top of the file. I don't know if you need that code in your files.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3937
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros