Parse thru text and return # on last line

January 31, 2010 at 03:07:55
Specs: Windows 7
I'd like a script to parse through a file and find the number before the comma of the last line. I'm working with text files that look like this:

1,some stuff,blah,more stuff
1,some stuff,blah,more stuff
2,some stuff,blah,more stuff
2,some stuff,blah,more stuff
3,some stuff,blah,more stuff
3,some stuff,blah,more stuff

in this case I'd want to the script to get 3 and set it to a variable var with the set command

Thanks in advance!


See More: Parse thru text and return # on last line

Report •


#1
January 31, 2010 at 03:25:13
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=1 delims=," %%a in (myfile) do (
set var=%%a
)
echo !var!


=====================================
Helping others achieve escape felicity

M2


Report •

#2
January 31, 2010 at 03:31:35
Save the below script using the name you like (e.g. num.bat) then at prompt

num PathName\FileName (e.g. num C:\My Folder\MyFile.txt)

@echo off
for /F "tokens=1 delims=," %%j in ('type "%*"') do set var=%%j
echo Last number is %var%


Report •

#3
January 31, 2010 at 07:45:44
thanks so much, both work great!

Report •
Related Solutions


Ask Question