如何替换"/"通过“;"在Windows上使用批处理将文件* .log转换为* .csv [英] How to replace "/" by ";" in files *.log to *.csv using batch on windows
问题描述
我有很多文件* .log包含以下行:
I have many files *.log containing the following lines:
11111/3333/45555/6666/2222//7777
11111/3333/45555/6666/2222//7777
,我需要将所有的"/"替换为;"产生以下结果:
and I need to replace all the "/" by ";" producing the following result:
11111; 3333; 45555; 6666; 2222 ;; 7777
11111;3333;45555;6666;2222;;7777
但是结果必须在同名文件中,但扩展名不同:* .csv. 如何在Windows上使用ms-dos批处理来做到这一点? PS:我不能使用.net,perl,vbscript或某些库.此脚本用于求职面试,他们想测试我是否知道Windows脚本.
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%
)
非常感谢.
推荐答案
就像这样:
@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...
)
这篇关于如何替换"/"通过“;"在Windows上使用批处理将文件* .log转换为* .csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!