我已经阅读了所有类似的问题,并尝试使用它来制作批处理脚本,但没有成功。
我有数百个txt文件都是这样开始的:(行之间没有空格)
SGCO Master Calibration Input Data, , , , , , , , , , , ,
, , , , , , , , , , , ,
Date,09-Sep-2014, ,Eng:,Tom, , , , , , , ,
Serial Number,201659, ,Dwt. No.,2177 Cal Date 04.10.2013,,,,,,,,
Gauge Pressure Range, 10K, ,Dwt. Correctio Factor,1.00128,,,,,,,,
Number of Temperatures,5, ,,,,,,,,,,
Number of Pressures,11, ,,,,,,,,,,
Calibration Temperature Unit, DEGC , ,,,,,,,,,,
Calibration Pressure Unit, PSIG , ,,,,,,,,,,
(逗号数量并不总是相同)
我想在我的文件名中使用以下变量:
10K
(在Range之后)
201659
(序列号后)
09-Sep-2014
(日期之后)
在这种情况下,文件名将为“SG10K - 201659 - 09-Sep-2014.txt
”
答案 0 :(得分:0)
setlocal enabledelayedexpansion
REM for all files do:
for %%f in (*.txt) do (
REM get desired lines and set variables:
for /f "tokens=1,2 delims=," %%i in (' findstr "^Date ^Serial Range," %%f') do set %%i=%%j
REM construct filename:
set "name=!Gauge Pressure Range: =SG! - !Serial Number! - !Date!.txt"
echo Filename is: "!name!"
)