tmhechler
asked on
Batch file to replace semicolons in text files with tildes.
I have text files in a folder (C:\tracking). I would like a batch file that will do a find and replace ove all the text inside the files that will change all of the semicolons (;) with the tilde (`).
I'm trying to get to files delimited with tildes (vendor import file requirement) from a system that will export files only with semicolons as delimters.
Can anyone help? (I've looked at almost every post in this place - going on 3 hours of trying now....I give up!!)
I'm trying to get to files delimited with tildes (vendor import file requirement) from a system that will export files only with semicolons as delimters.
Can anyone help? (I've looked at almost every post in this place - going on 3 hours of trying now....I give up!!)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Doing a find and replace is beyond the scope of batch files. What you can do instead is to write a very simple program, be it in C, VB, and write a batch file to process each of the exported files.
Also, when changing how a data file is delimited, i'd be very carefull, as the original program expects and handles the semicolon... so if you change all the ; to ', then if there are any occurances of the ' in the files, you're converted data will be corrupt.
Also, when changing how a data file is delimited, i'd be very carefull, as the original program expects and handles the semicolon... so if you change all the ; to ', then if there are any occurances of the ' in the files, you're converted data will be corrupt.
ASKER
I found two that I put together that worked. However, it will work on XP, but not on Win 2000. Any suggestions?
*****************begin batch file********************** *
@echo off
SET replace=
FIND /V "&" < import.dat> toproc.dat
FOR /F "tokens=1 delims=" %%i IN (toproc.dat) DO (
SET replace=%%i
CALL :PROCESS
)
FIND "&" < import.dat >>importnew.txt
DEL toproc.dat
:: MOVE /Y importnew.txt import.dat
GOTO End
:PROCESS
ECHO %replace:;=~%>>importnew.t xt
:END
*****************end batch file*********************
*****************begin batch file**********************
@echo off
SET replace=
FIND /V "&" < import.dat> toproc.dat
FOR /F "tokens=1 delims=" %%i IN (toproc.dat) DO (
SET replace=%%i
CALL :PROCESS
)
FIND "&" < import.dat >>importnew.txt
DEL toproc.dat
:: MOVE /Y importnew.txt import.dat
GOTO End
:PROCESS
ECHO %replace:;=~%>>importnew.t
:END
*****************end batch file*********************
BTW, this is a tilde: ~