0

我试图改变一些东西。

我在这里找到并替换:http: //www.dostips.com/?t=Batch.FindAndReplace

我想用制表符替换逗号。但是我替换 %1 %2 %3 是错误的。

@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION

@echo off set OldStr=,
@echo off set NewStr=\t
@echo off set FilePath=%UserProfile%\Desktop\information.csv

if "%OldStr%"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %FilePath%|find /n /v """') do (
    set "line=%%B"
    if defined line (
        call set "line=echo.%%line:%OldStr%=%NewStr%"
        for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
    ) ELSE echo.
)

我不确定 \t 是否有效。

我尝试更改命令,因为我需要 1 个批处理文件来完成我想要的所有操作。


原来的

@echo off
REM -- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION

::BatchSubstitude - parses a File line by line and replaces a substring"
::syntax: BatchSubstitude.bat OldStr NewStr File
::          OldStr [in] - string to be replaced
::          NewStr [in] - string to replace with
::          File   [in] - file to be parsed
:$changed 20100115
:$source http://www.dostips.com
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
    set "line=%%B"
    if defined line (
        call set "line=echo.%%line:%~1=%~2%%"
        for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
    ) ELSE echo.
)

我想在我自己的批处理文件上使用这个脚本。所以我需要通过一个var来改变参数。

4

1 回答 1

1

改变 , 在 \t

@echo off

REM -- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION

if /I "%~1"=="/h" goto:help
if "%UserProfile%\Desktop\%ComputerName%.csv"=="" goto:help

if ","=="" findstr "^::" "%~f0"&goto:help
for /f "tokens=1,* delims=]" %%A in ('"type %UserProfile%\Desktop\%ComputerName%.csv|find /n /v """') do (
    set "line=%%B"
    if defined line (
        call set "line=echo.%%line:,=   %%"
        for /f "delims=" %%X in ('"echo."%%line%%""')  do %%~X >> %UserProfile%\Desktop\%ComputerName%.csv_new
    ) ELSE echo.
)
move /Y %UserProfile%\Desktop\%ComputerName%.csv_new %UserProfile%\Desktop\%ComputerName%.csv >nul
于 2013-04-25T18:06:43.217 回答