我有一个txt文件,它是较早命令的输出。 这是txt文件的样子:
Uploading file 'Temp/output.mp4'...
Progress: 6.00 Mbps, 327680 / 10034413 (3.266%) ETA 14.82s
Progress: 5.85 Mbps, 999424 / 10034413 (9.960%) ETA 12.84s
Progress: 5.49 Mbps, 1687552 / 10034413 (16.818%) ETA 12.26s
Progress: 5.21 Mbps, 2310144 / 10034413 (23.022%) ETA 11.56s
Progress: 5.44 Mbps, 3014656 / 10034413 (30.043%) ETA 10.44s
Progress: 5.28 Mbps, 3686400 / 10034413 (36.738%) ETA 9.48s
Progress: 4.62 Mbps, 4161536 / 10034413 (41.473%) ETA 9.06s
Progress: 4.79 Mbps, 4849664 / 10034413 (48.330%) ETA 8.02s
Progress: 4.95 Mbps, 5439488 / 10034413 (54.208%) ETA 7.12s
Progress: 5.77 Mbps, 6242304 / 10034413 (62.209%) ETA 5.78s
Progress: 5.27 Mbps, 6897664 / 10034413 (68.740%) ETA 4.78s
Progress: 5.29 Mbps, 7553024 / 10034413 (75.271%) ETA 3.78s
Progress: 5.13 Mbps, 8159232 / 10034413 (81.312%) ETA 2.86s
Progress: 4.82 Mbps, 8749056 / 10034413 (87.191%) ETA 1.98s
Progress: 5.36 Mbps, 9469952 / 10034413 (94.375%) ETA 860ms
Progress: 4.62 Mbps, 10034413 / 10034413 (100.000%) ETA 0s
Upload successful! Video ID: XXXXXXXXXXX
Thumbnail uploaded!
我想将XXXXXXXXXXX提取到变量中。
这可能吗?
谢谢。
编辑: 我应该提一下,XXXXXXXXXXX每次都会有所不同:),以防不明显。
更新: 终于到达了我想要的位置:
for /f "tokens=2 delims=:" %%A in ('type log.txt ^| findstr "Video ID"') do set youtube=%%A
答案 0 :(得分:1)
假设InFile在当前文件夹中为Log.txt
,
下一批将
Upload
开头的行for /f
解析这些行,将其按字符:
或'
分成两部分Uploading file
还是Upload successful! Video ID
,并将第二部分分别存储到vars File / VideoID中。:: Q:\Test\2019\07\30\SO_57263881.cmd
@Echo off
Set "InFile=.\log.txt"
Set "File="
Set "VideoID="
for /f "tokens=1,2 delims=':" %%A in (
'findstr /I "^Upload" ^<"%InFile%"'
) Do if "%%A" equ "Uploading file " (
Set "File=%%B"
) else if "%%A" equ "Upload successful! Video ID" Set "VideoID=%%B"
if defined File if Defined VideoID (
Echo File : %File%
Echo VideoID: %VideoID:~1%
)
示例输出:
> Q:\Test\2019\07\30\SO_57263881.cmd
File : Temp/output.mp4
VideoID: XXXXXXXXXXX```