修改批次查找替换和使用选项卡

时间:2013-04-25 15:57:04

标签: batch-file

我寻找改变的东西。

我在这里找到并替换: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。

来改变参数

1 个答案:

答案 0 :(得分: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