用于从文件交换文本的批处理命令

时间:2016-03-06 07:50:35

标签: windows batch-file command

这是输入文件: -

Hello,1-23456
How are you,2-34567
.
.
.

我想要输出: -

1-23456,Hello
2-34567,How are you
.
.
.

请帮我为此创建一个批处理文件。

我试过这个

@echo off &setlocal

set "textfile=inputchq.csv"
set "newfile=output.txt"

(for /f "tokens=1,2 delims=," %%i in (%textfile%) do set srno=%%a&set comments=%%b (
    set "line=%%i"
    setlocal enabledelayedexpansion
set "line=%comments%,%srno%"
    echo(!line!
    endlocal
))>>"%newfile%"

但我没有得到所需的输出

1 个答案:

答案 0 :(得分:0)

@echo off &setlocal

set "textfile=inputchq.csv"
set "newfile=output.txt"

(for /f "tokens=1,2 delims=," %%a in (%textfile%) do (
    echo %%b,%%a"
))>>"%newfile%"

编辑以符合评论中的其他要求:

你需要延迟扩张并逃避特殊角色" |"

@echo off 
setlocal enabledelayedexpansion

set "textfile=inputchq.csv"
set "newfile=output.txt"

(for /f "tokens=1,2 delims=," %%a in (%textfile%) do (
    set "line=%%b,%%a"
    echo !line:^|=.!
))>>%newfile%