How to remove last blank line on a file

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
hpegar
Newbie
Posts: 9
Joined: Tue May 29, 2012 3:08 pm

How to remove last blank line on a file

Post by hpegar » Wed Jun 13, 2012 11:44 pm

Ive tried to make a line add mini macro

0122/12Firstone
Empty line here

What it does?
Well, i just click ADD, see what happens

0122/12Firstone
0124/12Second
Empty line here

But empty line continue

How to rid out of this? :?:

User avatar
Marcus Tettmar
Site Admin
Posts: 7393
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jun 14, 2012 2:34 pm

As we can't see your code we don't know how this file is being produced and why the blank line is there. We can give you code to remove a blank line from the end of a file, but wouldn't it be better if we could prevent the blank line from being output in the first place? We may be able to have a stab at that if we knew how the file was being created.

Anyhow, this code will remove a blank line from the end of a file:

Let>file=%SCRIPT_DIR%\test2.txt
ReadFile>file,filedata
Trim>filedata,filedata
DeleteFile>file
WriteLn>file,wlr,filedata

All it does is read the file in, trim the content, delete the original file and write it out again.

But, as I said, maybe we should look at how this blank line is winding up there in the first place and look to prevent that happening.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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