Better way to remove leading blank lines

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Better way to remove leading blank lines

Post by kpassaur » Sun Sep 19, 2010 9:18 am

I am looking for a better/faster way to remove blank lines of text at the begining of a file.

Currently I am doing this:


Code: Select all

Let>SLBL=True


        If>%SLBL%=True
        DeleteFile>%TEMP_DIR%test1.txt
            Let>k=1
            Let>BL=False
            Label>startrbl
            ReadLn>C:\Temp\blankline.txt,k,line
            
            If>line=##EOF##,finishrbl
            RegEx>[1+char],line,1,matches,num,0
            Let>tl=num
            
            If>BL=False
            
                If>tl>0
                WriteLn>%TEMP_DIR%test1.txt,result,line
                Let>BL=True
                Endif
            
            Else
            WriteLn>%TEMP_DIR%test1.txt,result,line
            Endif
                       
            Let>k=k+1
            Goto>startrbl
            Label>finishrbl
            ReadFile>%TEMP_DIR%test1.txt,testtext
            Endif
           
ExecuteFile>%TEMP_DIR%test1.txt

Now it works and all but on a large file 50+ pages it can take quite a while and I was wondering if someone new a quicker way of doing it.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Sun Sep 19, 2010 3:58 pm

Just do the replacement in memory instead like so:

Code: Select all

ReadFile>c:\file_with_blank_lines.txt,text
Let>pattern=^[\s]+|[\s]+$
RegEx>pattern,text,0,matches,num,1,,text
MessageModal>text

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Thanks

Post by kpassaur » Mon Sep 20, 2010 11:00 am

It works great, thank you

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts