Page 1 of 1

(SOLVED) .bat Find and Replace text

Posted: 31 Aug 2010 07:50
by jmituzas
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

Re: .bat Find and Replace text

Posted: 31 Aug 2010 08:50
by orange_batch
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:

Re: .bat Find and Replace text

Posted: 31 Aug 2010 09:14
by jmituzas
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

(SOLVED) .bat Find and Replace text

Posted: 31 Aug 2010 11:32
by jmituzas
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