Batch Delete Lines from .htm's in a Directory

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
chewbears
Posts: 1
Joined: 24 Aug 2010 07:31

Batch Delete Lines from .htm's in a Directory

#1 Post by chewbears » 24 Aug 2010 07:44

My htm files are all in a directory called D:\Batch
All the htm files have unquie names.
All the htm files are 44 lines
All the htm files are composed of strings
I need a batch to go through every text file (about 150) and remove lines certain lines.
lines 1-4 , 9-19 , 24-27 . 30-33 . and 39 - 44

I am sure if someone showed me how to run it on a specific line or set of lines I could figure it out.

Thanks!

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: Batch Delete Lines from .htm's in a Directory

#2 Post by orange_batch » 24 Aug 2010 08:49

This will do it all. Yay for double-nested for loops, lol.

Back up your data first. As usual, DOS may have problems with special characters.

Code: Select all

@echo off&echo:&color B&title Selective Line Remover by orange_batch&setlocal enabledelayedexpansion

for /r "D:\Batch" %%w in (*.htm) do (
for /f "delims=] tokens=1*" %%x in ('type "%%w" ^| find /v /n "" ^& type nul ^>"%%w"') do (
set removeline=0
for /l %%z in (1,1,4) do (
if "%%x"=="[%%z" set removeline=1
)
for /l %%z in (9,1,19) do (
if "%%x"=="[%%z" set removeline=1
)
for /l %%z in (24,1,27) do (
if "%%x"=="[%%z" set removeline=1
)
for /l %%z in (30,1,33) do (
if "%%x"=="[%%z" set removeline=1
)
for /l %%z in (39,1,44) do (
if "%%x"=="[%%z" set removeline=1
)
if !removeline!==0 (echo:%%y>>"%%w") else echo: - In %%~nxw removed line: %%x]&echo:
)
)
echo:   Press any key to exit.
pause>nul
exit

Post Reply