0

I have many files *.log containing the following lines:

11111/3333/45555/6666/2222//7777

and I need to replace all the "/" by ";" producing the following result:

11111;3333;45555;6666;2222;;7777

But the result must be in a file of the same name but just a differente extension: *.csv. How can I do this using ms-dos batch on windows? PS: I can't use .net, perl, vbscript or some library. This script if for a job interview and they want to test if I know Windows scripting.

I already tried to start but is not working...

@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "delims='/' tokens=*" %%i in ('findstr "\/" Input.txt') do (
    echo %%i
    set str=%%i
    set myvar=";"
    set str=%str:"/"=!myvar!%
    echo %str%
)

Many thanks in advance.

Arthur Accioly
  • 801
  • 9
  • 26

2 Answers2

2

Like this :

@echo off 
setlocal enabledelayedexpansion
for  %%a in (*.log) do (
  echo Working : %%a
  for /f "delims=" %%b in ('type %%a') do (
     set "$Line=%%b"
     set "$Line=!$Line:/=;!"
     echo !$Line!>>%%~na.csv)
 echo Done...
)
SachaDee
  • 9,245
  • 3
  • 23
  • 33
0

This uses a helper batch file called repl.bat (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place repl.bat in the same folder as the batch file or in a folder that is on the path.

@echo off
for %%a in (*.log) do type "%%a" |repl "/" ";" L > "%%~na.csv"
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • I can't use this repl.bat because this batch is for an interview that I'm going to have tomorrow. Do you have some solution without this? Thank you. – Arthur Accioly Jul 07 '14 at 23:56