Solved batch find and extract a line from file

March 20, 2012 at 03:59:17
Specs: Windows XP, 1 Gb
I have one file named list.txt which content is in the general form
dd/mm/yyyy;xxxxx;yyyy;zzzzz
dd/mm/yyyy;xxxxx;yyyy;zzzzzz
and so on….
The first token of each line is a date in the layout “dd/mm/yyyy”;
now I want to extract the corresponding line of today’s date and output result in a new file called today_list.txt

This is my attempt

@echo off > today_list.txt & setLocal enabledelayedexpansion

:: this is to set today’s date in a variable %today%
:: it’s fine in my case (because it’s dependent on user date layout)
for /f "tokens=1 delims=" %%a in ('date/t') do set today=%%a

:: but this is not ok because at this point I’ve lost the content of the variable %today%

for /f "tokens=1* delims=;" %%a in ('find "%today%" ^<list.txt') do (
echo %%b>today_list.txt
)

I can imagine the problem has to do with the proper storing of the variable inside the for loop but I can not work out any solution…(may be something related to the use of the exclamation points with variables??)

Any help for this?

Thanks


See More: batch find and extract a line from file

Report •


#1
March 20, 2012 at 05:26:10
✔ Best Answer
(may be something related to the use of the exclamation points with variables??)
Except you're not using any exclamation points with your variables?

Leave echo on, and see what it's doing. Then you might see what I see.

How To Ask Questions The Smart Way


Report •

#2
March 20, 2012 at 06:13:33
thanks razor for the debugging hint

as usual (apparently) tiny things rule the (programming) world!

...and finally this is the amended snippet of code
for /f "tokens=1" %%a in ('date/t') do set today=%%a

bye

max


Report •

Related Solutions


Ask Question