Batch Delete Lines from .htm's in a Directory

August 24, 2010 at 06:45:49
Specs: Windows XP
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.


See More: Batch Delete Lines from .htms in a Directory

Report •

August 24, 2010 at 06:59:30
download sed for windows then do this

c:\> sed -i.bak "1,4d;9,19d;24,27d;30,33d;39,44d" file.html

use a for loop to loop through your files, then execute with the above at each iteration

for /f .... ( ..... ) do (
  sed ....

GNU win32 packages | Gawk

Report •

August 24, 2010 at 07:09:36
Thanks for the reply Ghostdog,

I installed sed. I then created a test file named, "filename.htm" opened the cmd and typed your code. On a single file it worked great. Then I tried to do

sed -i.bak "1,4d;8,19d;24,27d;30,33d;39,44d" file1.html
sed -i.bak "1,4d;8,19d;24,27d;30,33d;39,44d" file2.html

and save as a .bat file and it worked. But how would I have written the for loop. Could you please assist on that? Thanks assume my files are named file1 and file2 for ease. Thanks Would just like to know : P

Report •

August 24, 2010 at 07:46:29
A simple search on google for "batch file for loops" would produce many results you can look into. I shouldn't have to write it for you. Please do the research, then try and follow the examples people have written. Come here again if you hit problems. Another alternative is to search this forum. the for loop is indispensable in batch scripting and you can find them in almost all the answers posted here.

GNU win32 packages | Gawk

Report •

Related Solutions

August 24, 2010 at 07:49:51
Was just staying in the dialogue, while I wrote the batch file. I would have searched if you didn't respond or responded with go search. Thanks for your help on the sed program. Googling will get me the rest of the way in the learning process.

Report •

Ask Question