[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 699
  • Last Modified:

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!!)

0
tmhechler
Asked:
tmhechler
1 Solution
 
Julian HansenCommented:
I don't think this easily doable in a batch file without some external utility like SED

http://www.student.northpark.edu/pemente/sed/

Alternatively there are apps out there that will do this for you.

http://www.divlocsoft.com/
http://www.programmersheaven.com/zone16/cat656/
http://www.ashleybrown.co.uk/dotedit/docs/searching/infiles.asp
http://www.tucows.com/preview/341087.html

0
 
PreeceCommented:
If using vb or vbscript is an option, this may be pretty easy...

BTW, this is a tilde:  ~

0
 
phonglongCommented:
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.
0
 
tmhechlerAuthor Commented:
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.txt

:END

*****************end batch file*********************
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now