Removing substring in a file with batch

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

I have a file having contents as:

I am trying to remove http://sharepoint.company/ 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
  • 2
LVL 33

Assisted Solution

knightEknight earned 300 total points
ID: 26213177
Download this command-line search/replace tool:  http://www.paulslore.com/utils/chgstr.zip

Then you can remove the string like this:

   chgstr.exe  "http://sharepoint.company/"  ""  myfile.txt
LVL 33

Assisted Solution

knightEknight earned 300 total points
ID: 26213192
It will also work on multiple files and it will traverse sub-folders:

  chgstr.exe  "http://sharepoint.company/"  ""   *.txt  /s
LVL 38

Accepted Solution

Shift-3 earned 700 total points
ID: 26213252
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:http://sharepoint.company/=!
 echo !line! >> "%output%"

Open in new window


Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

840 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