如果我的.txt包含以下内容:
2005050“2005年2月19日”
2005060“3/1/2005”
2005070“3/11/2005”
2005080“3/21/2005”
2005090“3/31/2005”
是否有办法让批处理文件读取并始终在7的字符末尾添加.png。
例如。
2005050.png“2005年2月19日”
2005060.png“3/1/2005”
2005070.png“3/11/2005”
2005080.png“3/21/2005”
2005090.png“3/31/2005”
答案 0 :(得分:3)
此批处理文件将在第一个空格处拆分每一行,并在拆分前将.png附加到字符串。该脚本从infile.txt读取行并输出到outfile.txt。
@echo off
echo. > outfile.txt
for /f "tokens=1*" %%i in (infile.txt) do echo %%i.png %%j >> outfile.txt
<强>更新强>
或者先删除outfile.txt ....
@echo off
del /q /f outfile.txt
for /f "tokens=1*" %%i in (infile.txt) do echo %%i.png %%j >> outfile.txt
另一次更新
要向outfile.txt添加新记录,请执行类似....
的操作@echo off
for /f "tokens=1*" %%i in (infile.txt) do (
find "%%i.png %%j" outfile.txt > nul
if errorlevel 1 then (
echo %%i.png %%j >> outfile.txt
)
)
答案 1 :(得分:0)
sed -r "s/^(.......)(.*)/\1.png\2/" file
答案 2 :(得分:0)
我的回答失败了:我确实尝试过:但我无法让FOR在
中工作@echo off
set str1=ooo
set str2=ppp
for /f "tokens=*" %%a in ('type testprog.txt') do (
set str=!%%a!
echo %%str:~0,7%%.png %%str:~-5,14%% >> tempprog.txt
)
move tempprog.txt testprog.txt
start testprog.txt
也许有人可以编辑工作版本,因为我希望看到什么 我做错了......