(SOLVED) .bat Find and Replace text

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jmituzas
Posts: 13
Joined: 30 Aug 2010 08:43

(SOLVED) .bat Find and Replace text

#1 Post by jmituzas » 31 Aug 2010 07:50

I have some files that contain some of if not all of the following:

Program RxBIN RXPCN RxGroup MemberID

not all files will have all of those headers but the ones that do I will need to replace so it looks like this:

@Program @RxBIN @RXPCN @RxGroup @MemberID


Thanks in Advance,
Joe
Last edited by jmituzas on 31 Aug 2010 11:33, edited 1 time in total.

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

Re: .bat Find and Replace text

#2 Post by orange_batch » 31 Aug 2010 08:50

It's not too hard to write the batch for that if those words aren't mixed in with a bunch of other data, since it would just require comparing 5 tokens to 5 words, but DOS needs to rewrite each file too. I'm betting on this being easier for gawk (ghostmachine), I'm too tired to write anything right now. :roll:

jmituzas
Posts: 13
Joined: 30 Aug 2010 08:43

Re: .bat Find and Replace text

#3 Post by jmituzas » 31 Aug 2010 09:14

orange_batch wrote:It's not too hard to write the batch for that if those words aren't mixed in with a bunch of other data, since it would just require comparing 5 tokens to 5 words, but DOS needs to rewrite each file too. I'm betting on this being easier for gawk (ghostmachine), I'm too tired to write anything right now. :roll:


Thanks for the input... I am realizing that it is alot easier to come up with these kind of solutions in sed, awk, or even perl. But these are to be transfered to windows desktops, and I don't think that windows will interpret those without installing a 3rd party app to all the desktops in question.

Thanks anyways,
Joe

jmituzas
Posts: 13
Joined: 30 Aug 2010 08:43

(SOLVED) .bat Find and Replace text

#4 Post by jmituzas » 31 Aug 2010 11:32

I found the solution http://www.dostips.com/?t=Batch.FindAndReplace

had to rewite it a bit to actually get the job done.

I am sure there is an easier way of doing this but I got it to work :wink:

call BatchSubstitute.bat Program @Program InDesignData.txt >newfile.txt

if not exist newfile.txt goto skip
del "InDesignData.txt"
ren "newfile.txt" "InDesignData.txt"
:skip

call BatchSubstitute.bat RxBIN @RxBIN InDesignData.txt >newfile.txt
if not exist newfile.txt goto skip
del "InDesignData.txt"
ren "newfile.txt" "InDesignData.txt"
:skip

call BatchSubstitute.bat RXPCN @RXPCN InDesignData.txt >newfile.txt
if not exist newfile.txt goto skip
del "InDesignData.txt"
ren "newfile.txt" "InDesignData.txt"
:skip

call BatchSubstitute.bat RxGroup @RxGroup InDesignData.txt >newfile.txt
if not exist newfile.txt goto skip
del "InDesignData.txt"
ren "newfile.txt" "InDesignData.txt"
:skip

call BatchSubstitute.bat MemberID @MemberID InDesignData.txt >newfile.txt
if not exist newfile.txt goto skip
del "InDesignData.txt"
ren "newfile.txt" "InDesignData.txt"
:skip

Post Reply