我必须处理一个文本文件,其中包含一系列看起来像
的事件event_name1 : dd.mm.yyyy
event_name2 : dd.mm.yyyy
...
enemt_nameN : dd.mm.yyyy
我不知道手前有多少行
然后,我必须从每一行中提取一个日期,然后解析它以找到我要查找的日期。 如果日期是所需日期,我需要回显事件名称并继续搜索
我可以逐行解析文件,但是一行不会拆分。我到处都在使用与您可能在下面看到的相同的命令
@echo off
rem parsing today's date and saving variables i will need later
echo %date%
for /f "tokens=1-3 delims=-" %%a in ("%date%") do (
set day = %%a
set month = %%b
set year = %%c
)
rem parsing the file with events
FOR /F "tokens=*" %%i IN (Dates.txt) DO (
rem trying to work with the current line
for /f "tokens=1-3 delims= " %%j in (%%i) do (
set /f name = %%a
set /f inputdate = %%c
rem doing stuff with the date in the line, i need to parse it by day, month and year
for /f "tokens=1-3 delims=." %%k in (%inputdate%) do (
if /I "%day%" EQU %%a echo %inputdate%
)
)
)
我希望行能正常分割,但是,在尝试解析字符串的每个循环中,我都会不断收到诸如“无法找到文件event_name”之类的错误消息
cmd中的echo输出如下所示:
(for /F "tokens=1-3 delims= " %j in (tomorrow : 12.06.2019) do (
set /f name = %a
set /f inputdate = %c
for /F "tokens=1-3 delims=." %k in ((null)) do (if /I "" EQU %a echo
)
) )
Unable to find the file tomorrow.
答案 0 :(得分:0)
当我正确理解您的尝试后,下面的一句话就足够了:
for /f "delims=:" %%a in ('type Dates.txt^|find "%date%"') do @echo %%a