Batch file to replace semicolons in text files with tildes.

Posted on 2005-05-03
Last Modified: 2012-05-05
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!!)

Question by:tmhechler
    LVL 50

    Accepted Solution

    I don't think this easily doable in a batch file without some external utility like SED

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

    LVL 12

    Expert Comment

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

    BTW, this is a tilde:  ~


    Expert Comment

    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.

    Author Comment

    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

    FIND "&" < import.dat >>importnew.txt
    DEL toproc.dat
    :: MOVE /Y importnew.txt import.dat
    GOTO End

    ECHO %replace:;=~%>>importnew.txt


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

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    add text to end of existing text in file 16 54
    userCompare  challenge 3 54
    endX challenge 2 33
    strDist challenge 35 70
    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now