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!
Batch Delete Lines from .htm's in a Directory
Moderator: DosItHelp
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Batch Delete Lines from .htm's in a Directory
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.
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