Batch Script to format 30,000 text files in multiple folders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
brisjast
Posts: 1
Joined: 27 Jul 2011 04:48

Batch Script to format 30,000 text files in multiple folders

#1 Post by brisjast » 27 Jul 2011 04:52

Hello

Hoping someone will be able to assist

I have 30,000 .txt files split across 200 or so subfolders all contained within a main folder.

Is there a way to automatically read each file and strip out all linebreaks and carriage returns via a DOS batch script?

I am having trouble importing these files into another piece of software because of the linebreaks and cant face manually editing 30000 files!

Thank you in advance for assistance :wink:


dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Batch Script to format 30,000 text files in multiple fol

#3 Post by dbenham » 28 Jul 2011 06:13

I don't think the post renzlo suggested will help - It removes empty lines. It does not strip all <end of line> characters.

@brisjast - Are you sure your stated requirement is precise :?:

If you simply strip all <end of line> characters, then:
This
little
file
is
readable.

What
to
do
with
blank
lines?

Becomes unreadable
Thislittlefileisreadable.Whattodowithblanklines?


I suspect you want to preserve empty lines and for the rest you want to replace each <end of line> with a <space>:
This little file is readable.

What to do with blank lines?


The pure batch solution is not too difficult, but it will be slow for 30000 files. It would be better if you could locate a good text editor that allows search and replace of <end of line> that is also scriptable. If you find one that can do the search and replace but isn't scriptable, you can automate the process with AutoIT.

Better yet would be a text processing utility like perl or sed. Both are available for Windows for free.

Reply if you still want a pure batch solution, along with clarified requirements. It might be a few days before I have time to develop a solution. Someone else might beat me to it.

Dave Benham

Post Reply