bat命令处理txt文档,功能如下:1.txt文档拖入cmd;2.读取txt文档,获取每一行的每一个元素,元素间以“,”分隔;3.将每一行的第二个元素修改为“1”;4.将每一行的第三个元素开头增加“3”;5.将每一行的第四个元素开头增加“38”;6.输出修改后的txt文档。
时间: 2024-03-05 21:53:37 浏览: 73
你可以使用以下的bat命令来实现该功能:
```
@echo off
setlocal enabledelayedexpansion
set /p filename=Please drag the txt file here:
for /f "tokens=* delims=" %%a in (%filename%) do (
set "line=%%a"
set "tok=1"
set "newline="
for %%b in (!line!) do (
if !tok! EQU 2 (
set "newline=!newline!1,"
) else if !tok! EQU 3 (
set "newline=!newline!3%%b,"
) else if !tok! EQU 4 (
set "newline=!newline!38%%b,"
) else (
set "newline=!newline!%%b,"
)
set /a "tok+=1"
)
echo !newline:~0,-1!>> modified.txt
)
echo.
echo The modified txt file has been saved as "modified.txt".
pause
```
你只需将以上命令复制到文本编辑器中,将其保存为 ".bat" 文件,然后将要修改的 txt 文件直接拖拽到 cmd 窗口中即可。程序将输出修改后的 txt 文件,命名为 "modified.txt"。
阅读全文