Removing substring in a file with batch

Posted on 2010-01-08
Last Modified: 2012-05-08
Hi there;

I have a file having contents as:

I am trying to remove parts in a batch, yet I am not successfuly.

Could you fix my code please?

Best regards.
for /f "tokens=* delims=" %%a in (myfile.txt) do (

set str=%%a

set str=%str:http=%

ECHO %str% >> filecopy.txt)


Open in new window

Question by:jazzIIIlove
    LVL 33

    Assisted Solution

    Download this command-line search/replace tool:

    Then you can remove the string like this:

       chgstr.exe  ""  ""  myfile.txt
    LVL 33

    Assisted Solution

    It will also work on multiple files and it will traverse sub-folders:

      chgstr.exe  ""  ""   *.txt  /s
    LVL 38

    Accepted Solution

    Generally speaking, you shouldn't use batch scripting for text editing.  It strips blank lines and chokes on special characters.  However, if you really must, here's how you could do it.

    @echo off
    setlocal enabledelayedexpansion
    set input=myfile.txt
    set output=filecopy.txt
    for /f "tokens=*" %%G in ('type "%input%"') do (
     set line=%%G
     set line=!line:!
     echo !line! >> "%output%"

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT ( The crux of this batch f…
    This article was inspired by a question here at Experts Exchange ( The requirements stated in that question are (1) reduce the file size of a large number of…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video discusses moving either the default database or any database to a new volume.

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now