Sorting a text file by date with windows batch script -
i have in interesting issue, need sort list of items date in text file this:
http://www.boatus.com/sailing,1/21/2013 9:00 pm http://www.boatus.com/powerboat,3/21/2012 10:00 pm http://www.boatus.com/games.html,5/20/2013 10:00 pm http://www.boatus.com/,4/11/2013 10:00 pm http://www.boatus.com/pressroom/prrss.asp,4/21/2013 10:00 pm http://www.boatus.com/,4/20/2013 9:00 pm i need 100 days of history. if today 5/10/2013, want 1/30/2013 - 5/10/2013. hence list above should after sorting :
http://www.boatus.com/,4/11/2013 10:00 pm http://www.boatus.com/,4/20/2013 9:00 pm http://www.boatus.com/pressroom/prrss.asp,4/21/2013 10:00 pm http://www.boatus.com/games.html,5/20/2013 10:00 pm hence past 100 days listed in order date.
here's version since i've written - didn't bother 'last 100 days' part makes easy if change mind.
@echo off setlocal enabledelayedexpansion ( /f "tokens=1*delims=, " %%h in (swydf.txt) ( /f "tokens=1-7delims=/: " %%a in ("%%i") ( set /a rmonth=10+%%a set /a rday=10+%%b set /a rhour=10+%%d if %%d==12 (set rhour=10) echo %%c!rmonth!!rday!%%f!rhour!%%e,%%h,%%i ) ) )>sorttemp.txt ( /f "tokens=1*delims=," %%i in ('sort ^<sorttemp.txt') echo %%j )>output.txt type output.txt del sorttemp.txt /f /q goto :eof essentially, date , time elements converted constant-length field each adding 10 (since bar minutes 1..31 - making 11..41) setting hour 10 if it's 12 (thus 12am->10 sorts before 1am->11)
sort result of year+month+day+ampm+hour+min+,+http...+,+data , output remainder after first token (delimited comma)
Comments
Post a Comment