batch file to alter txt files through multiple find and replace

Josef Miller

Junior Member
Mar 7, 2018
7
0
1
I'm working on analysing data in txt format.
Data are in about 22000 files, in one main directory under many sub and sub sub-directories.
Each file has a different number of data records.
Each data record starts with the word "Type" and consists of a number of segments separated by "%" (percent character).

In order to run data analysis, I need to change the format of every data file so that:
1. first find and replace % with regex \r\n (a newline or carriage return), so that the segments will be in successive order, and
2. then find and replace the word Type with a new line above it, i.e. with \r\nType, so that each record is separated with one empty line from the record above.

I usually do this manually for a handful number of files, but when it comes to thousands of them I become in need for an expert hand to help. So can I get some precious assistance with this request, please?

Many thanks in advance.

J.
 

veri745

Golden Member
Oct 11, 2007
1,163
4
81
People are a lot more likely to help if you ask a specific question, or post a code clip where you're having a particular issue you need help with.

Asking for people to do something for you may not get much response.
 

Josef Miller

Junior Member
Mar 7, 2018
7
0
1
@mxnerd & veri745, thank you for your comments. There are times when we tend to go to restaurants despite we can cook, simply because we're tired or don't have time to spend on cooking. We should all be more cooperative and more understanding. When someone asks for help, it doesn't mean at all that that person is lazy or ignorant or need some literature to read and learn. It simply means that such person needs help. And believe me, there are a lot of people who tend to help just for help, simply because they love doing the good.

I found this powerful "find and replace utility" at this link: http://findandreplace.io/ through which I fulfilled my need. I hope it would be of some benefit to someone "in need".

At this point I close this thread, and it can be marked as "resolved".

J.
 

mxnerd

Diamond Member
Jul 6, 2007
6,799
1,103
126
Not that I don't want to help, it's that I haven't program for a while. o_O

I assume it's your daily job to process text files since you posted 2 similar threads in a row,

that's why I suggested you to learn some programming, since that maybe what you need down the road.

Since you already found your solution, congratulate that!
 

mv2devnull

Golden Member
Apr 13, 2010
1,526
160
106
I have 'bash', 'find' and 'sed' at my disposal and thus consider the task "easy".
The twist, of course is that those GNU tools, while being available for Windows too, are not "batch".
 

sourceninja

Diamond Member
Mar 8, 2005
8,805
65
91
I have 'bash', 'find' and 'sed' at my disposal and thus consider the task "easy".
The twist, of course is that those GNU tools, while being available for Windows too, are not "batch".
Simple answer is to just use powershell for windows scripts.

Longer answer is to either install gnu tools, or enable the linux subsystem on windows and use the same scripts.
 

mv2devnull

Golden Member
Apr 13, 2010
1,526
160
106
Thus we can summarize that "batch", "powershell", and "sh/ksh/csh/tcsh/bash" scripts are all "easy", but one has to learn at least one of them first.
 

purbeast0

No Lifer
Sep 13, 2001
53,543
6,368
126
This can very easily be done using any programming language. If I were to do this I'd write it in Java. Open a file stream, do a find and replace on each line, then output the results. You can easily get all of the files in a specific directory and traverse the folders then process them.