我有这个批处理脚本,它运行4个不同的文本文件(IMSI1.txt IMSI2.txt等),在其中搜索-imsi并输出旁边的值。
@echo off
setlocal EnableDelayedExpansion
set N=4
for /L %%r in (1,1,%N%) do (
for /F "delims=" %%a in ('findstr /C:"-imsi" IMSI%%r.txt') do set line=%%a
for /F %%a in ("!line:*-imsi=!") do echo %%a>> out & echo %%a> N%%r.txt
)
实施例
Hello this is the text file
asdasd -imsi 367
asdasd -imsi 888
输出
888
所需输出
367
888
如何修复输出?
答案 0 :(得分:2)
你快到了那里:
@echo off
setlocal EnableDelayedExpansion
set N=1
for /L %%r in (1,1,%N%) do (
for /F "delims=" %%a in ('findstr /C:"-imsi" IMSI%%r.txt') do (
set line=%%a
for /F %%a in ("!line:*-imsi=!") do echo %%a>> out & echo %%a> N%%r.txt
)
)