通过批处理脚本拆分文本文件时省略了感叹号
While splitting txt file through batch script Exclamations are ommitting
我是批处理脚本的新手,在这里我尝试将我的文本文件分成每 100 万行的块。
块文件按我的预期生成,但在输出文件内容中,我缺少感叹号 (!),甚至跳过感叹号后的直接列。请帮助我将原始文件中的数据分成块!
@ECHO OFF
setLocal DisableDelayedExpansion
set limit=1000000
set feed_name=test.txt
set file=%Tgt_Dir%\%feed_name%
set lineCounter=1
set filenameCounter=1
set name=
set extension=
for %%a in (%file%) do (
set "name=%%~na"
set "extension=%%~xa"
)
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (%file%) do (
set splitFile=!name!%date:~12,2%%date:~4,2%%date:~7,2%!filenameCounter!!extension!
if !lineCounter! gtr !limit! (
set /a filenameCounter=!filenameCounter! + 1
set lineCounter=1
echo Created !splitFile!.
)
echo %%a>> %Tgt_Dir%\!splitFile!
set /a lineCounter=!lineCounter! + 1
)
endlocal
这是一个制表符分隔符文件。
截图
您需要切换延迟展开。
setlocal DisableDelayedExpansion
for /f "tokens=*" %%a in (%file%) do (
Set "line=%%a"
setlocal EnableDelayedExpansion
set splitFile=!name!%date:~12,2%%date:~4,2%%date:~7,2%!filenameCounter!!extension!
echo(!line!>> %Tgt_Dir%\!splitFile!
if !lineCounter! gtr !limit! (
ENDLOCAL
set /a filenameCounter+=1
set lineCounter=1
echo Created file
) ELSE ENDLOCAL
set /a lineCounter=lineCounter + 1
)
我是批处理脚本的新手,在这里我尝试将我的文本文件分成每 100 万行的块。 块文件按我的预期生成,但在输出文件内容中,我缺少感叹号 (!),甚至跳过感叹号后的直接列。请帮助我将原始文件中的数据分成块!
@ECHO OFF
setLocal DisableDelayedExpansion
set limit=1000000
set feed_name=test.txt
set file=%Tgt_Dir%\%feed_name%
set lineCounter=1
set filenameCounter=1
set name=
set extension=
for %%a in (%file%) do (
set "name=%%~na"
set "extension=%%~xa"
)
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (%file%) do (
set splitFile=!name!%date:~12,2%%date:~4,2%%date:~7,2%!filenameCounter!!extension!
if !lineCounter! gtr !limit! (
set /a filenameCounter=!filenameCounter! + 1
set lineCounter=1
echo Created !splitFile!.
)
echo %%a>> %Tgt_Dir%\!splitFile!
set /a lineCounter=!lineCounter! + 1
)
endlocal
这是一个制表符分隔符文件。
截图
您需要切换延迟展开。
setlocal DisableDelayedExpansion
for /f "tokens=*" %%a in (%file%) do (
Set "line=%%a"
setlocal EnableDelayedExpansion
set splitFile=!name!%date:~12,2%%date:~4,2%%date:~7,2%!filenameCounter!!extension!
echo(!line!>> %Tgt_Dir%\!splitFile!
if !lineCounter! gtr !limit! (
ENDLOCAL
set /a filenameCounter+=1
set lineCounter=1
echo Created file
) ELSE ENDLOCAL
set /a lineCounter=lineCounter + 1
)