Board logo

标题: [文本处理] 获取txt的行内容作为变量按指定格式生成对应的BAT文件 [打印本页]

作者: ccw4234312    时间: 2014-11-6 12:51     标题: 获取txt的行内容作为变量按指定格式生成对应的BAT文件

TXT 内容

5678932   a12.docx

1234564   b23.docx

1244444   c34.docx

1243424   d23.docx

N 行

BAT 内容

echo ^<attachment:a12.docx^> >> ~1.txt
echo ^<to_num:5678932^> >> ~1.txt
test
echo ^<attachment:b23.docx^> >> ~2.txt
echo ^<to_num:1234564^> >> ~2.txt
test
echo ^<attachment:c34.docx^> >> ~3.txt
echo ^<to_num:1244444^> >> ~3.txt
test
echo ^<attachment:d23.docx^> >> ~4.txt
echo ^<to_num:1243424^> >> ~4.txt
test
echo ^<attachment:xxxx.docx^> >> ~n.txt
echo ^<to_num:xxxx> >> ~n.txt
test
作者: cyq8886    时间: 2014-11-7 15:39

input.txt 是TXT 文件名
  1. @echo off
  2. echo. >demo.bat
  3. set num=1
  4. setlocal enabledelayedexpansion
  5. for /F "eol= tokens=1* delims= " %%i in (input.txt) do (
  6.   echo echo ^^^^^<attachment:%%j^^^^^> ^>^> ~!num!.txt >>demo.bat
  7.   echo echo ^^^^^<to_num:%%i^^^^^> ^>^> ~!num!.txt >>demo.bat
  8.   set /a num+=1
  9. )
  10. echo ok
  11. pause>nul
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2