Link to home
Start Free TrialLog in
Avatar of Duke001
Duke001Flag for United Kingdom of Great Britain and Northern Ireland

asked on

batch to iterate in delete first blank line of each htm file

Hi Experts,

I need to iterate over all files (htm) in a folder and get rid of the first line which is blank.

Thanks,
Duke001
Avatar of TvMpt
TvMpt
Flag of Portugal image

This should work in batch file, just add this code into .bat file)
@echo off
for %%x in (*.html) do (
    more +1 "%%x" >tmp
    move /y tmp "%%x"
)

Open in new window

Avatar of Duke001

ASKER

Hi TvMpt

At the first glance it seems to work perfectly. Please let me do some further checks and I will let you know in the next hour or so and assign the points to you.

Many thanks,
Duke001
Avatar of Duke001

ASKER

I am sorry to push my luck but would it be possible to modify the code in order to give it more flexibility and run it from anywhere (ex. set BaseDir= )

Many thanks
Duke001
You want to the folder as parameter?
Avatar of Duke001

ASKER

Basically I want to be able to indicate where the the htm files are.
@echo off
for %%x in (%1*.html) do (
    more +1 "%%x" >tmp
    move /y tmp "%%x"
)

Open in new window


Run it like ->   script.bat c:\folder\
Avatar of Bill Prew
Bill Prew

I need to iterate over all files (htm) in a folder and get rid of the first line which is blank.
Is it line #1 you always want to remove, or the first line that is blank (meaning some non-blank lines could come before it)?

~bp
Avatar of Duke001

ASKER

I am attaching a sample.htm file which shows exactly what I am looking for.
The first line of the file which is blank followed by ".## blablabla" as seen in the example, must be wiped.

Thanks

PS: do you know a method to convert the Encoding from UTF in UTF-8 to UTF in UTF-8 without BOM

If yes please let me know and I will increase the points
Batch.zip
http://www.sttmedia.com/textencoder-batch-version

or you can use the notepad++.

 Notepad++ > Encoding > Convert to UTF-8 without BOM
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Duke001

ASKER

Hi,

Please see attached file which contains the error message when running (my OS is XP Pro SP3)

Is it possible to incorporate the batch command (software you recommended) into this vbs in order to do the encoding ?

Thanks,

PS: I did not forget to increase the points
VBS-ERROR.tif
Can you determine which file it errored on?  Take a look at the files in the test folder and sort by last update and see if it worked on any?  I'd like to get a copy of the file it is having trouble with.

It should take care of the UTF BOM already.

~bp
Avatar of Duke001

ASKER

Strangely I have tried to reproduce the same problem but everything seems to running smoothly now.
So, if you would kindly do the "Encoding" bit I would be grateful and of course (again) I will not forget to increase the points.

PS: I believe that I need to by the piece of software from "Stefan Trost Media", am I right?
So, if you would kindly do the "Encoding" bit I would be grateful
It should already be doing this, let me know if it isn't.

~bp
Avatar of Duke001

ASKER

You are completely right.
Because I didn't see the code where this encoding is takes action I've just assumed (wrongly!) that the encoding was not ready. Just to trying to understand, where is that encoding statement?

Many thanks for doing this.
The MID() strips off the 4 byte BOM that you seemed to have (although it was after the first CR,LF pair, which seemed odd), and the OpenTextFile defaults to writing the file in ANSI mode.

~bp
Avatar of Duke001

ASKER

Thanks for the explanation.
This means that wherever the htm files encoding are this "vbs" will do the businesses! Is this correct?

As promised I have increased the points up to 500
Yes.  Just make sure you test fully in case you have files that are different than the one you showed me.

~bp
Avatar of Duke001

ASKER

ok, thanks again.
have a nice weekend.