sort by date a log file

  • Thread starter Thread starter Gustavio
  • Start date Start date
G

Gustavio

Hello,

I have a log file like this :
[...]
HTCHAD06A,00C04F0CC49B,2005/07/07 10:43:59
HTCHFT10,005070023E6D,2004/11/18 17:17:52
HTCOPD01,000629A6EF36,2005/07/07 16:03:24
HTCPED01,0000395FEAD2,2004/12/21 14:28:26
[...]

And I need to sort it with a batch file by date ( from the oldest to the
newest).

I don't know how to do this...
Could someone help me ?

Thanks
Gus.
 
Hello,

I have a log file like this :
[...]
HTCHAD06A,00C04F0CC49B,2005/07/07 10:43:59
HTCHFT10,005070023E6D,2004/11/18 17:17:52
HTCOPD01,000629A6EF36,2005/07/07 16:03:24
HTCPED01,0000395FEAD2,2004/12/21 14:28:26
[...]

And I need to sort it with a batch file by date ( from the oldest to the
newest).

I don't know how to do this...
Could someone help me ?

Thanks
Gus.

call SortMyLog c:\folder\MyLog.log


@echo off
if {%1}=={} @echo Syntax: call SortMyLog LogFilePath&goto :EOF
if not exist %1 @echo Syntax: call SortMyLog LogFilePath - %1 does NOT exist.&goto :EOF
setlocal
set MyLog=%1
set wrk1="%TEMP%\SortMyLog_%RANDOM%.TM1"
set wrk2="%TEMP%\SortMyLog_%RANDOM%.TM2"
if exist %wrk% del /q %wrk%
for /f "Tokens=*" %%a in ('type %MyLog%') do (
for /f "Tokens=3 Delims=," %%d in ('@echo %%a') do (
@echo %%d;%%a>>%wrk1%
)
)
sort %wrk1% /O %wrk2%
del /q %MyLog%
for /f "Tokens=1* Delims=;" %%a in ('type %wrk2%') do (
@echo %%b>>%MyLog%
)
del /q %wrk1%
del /q %wrk2%
endlocal
 
Hi Jerold,

Thanks for the script. It's grat help.

It works perfectly.
But if I give another name than SortMyLog.bat to the file, an error message
appears. :
" Maximun setlocal recussion level reached"

I can't figure out why... Do you know ?

Thanks again,
Gus.

Jerold Schulman said:
Hello,

I have a log file like this :
[...]
HTCHAD06A,00C04F0CC49B,2005/07/07 10:43:59
HTCHFT10,005070023E6D,2004/11/18 17:17:52
HTCOPD01,000629A6EF36,2005/07/07 16:03:24
HTCPED01,0000395FEAD2,2004/12/21 14:28:26
[...]

And I need to sort it with a batch file by date ( from the oldest to the
newest).

I don't know how to do this...
Could someone help me ?

Thanks
Gus.

call SortMyLog c:\folder\MyLog.log


@echo off
if {%1}=={} @echo Syntax: call SortMyLog LogFilePath&goto :EOF
if not exist %1 @echo Syntax: call SortMyLog LogFilePath - %1 does NOT exist.&goto :EOF
setlocal
set MyLog=%1
set wrk1="%TEMP%\SortMyLog_%RANDOM%.TM1"
set wrk2="%TEMP%\SortMyLog_%RANDOM%.TM2"
if exist %wrk% del /q %wrk%
for /f "Tokens=*" %%a in ('type %MyLog%') do (
for /f "Tokens=3 Delims=," %%d in ('@echo %%a') do (
@echo %%d;%%a>>%wrk1%
)
)
sort %wrk1% /O %wrk2%
del /q %MyLog%
for /f "Tokens=1* Delims=;" %%a in ('type %wrk2%') do (
@echo %%b>>%MyLog%
)
del /q %wrk1%
del /q %wrk2%
endlocal
 
I can't imagine.

If you named it with an embedded space, you must use " marks to encapsulate any reference to it.




Hi Jerold,

Thanks for the script. It's grat help.

It works perfectly.
But if I give another name than SortMyLog.bat to the file, an error message
appears. :
" Maximun setlocal recussion level reached"

I can't figure out why... Do you know ?

Thanks again,
Gus.

Jerold Schulman said:
Hello,

I have a log file like this :
[...]
HTCHAD06A,00C04F0CC49B,2005/07/07 10:43:59
HTCHFT10,005070023E6D,2004/11/18 17:17:52
HTCOPD01,000629A6EF36,2005/07/07 16:03:24
HTCPED01,0000395FEAD2,2004/12/21 14:28:26
[...]

And I need to sort it with a batch file by date ( from the oldest to the
newest).

I don't know how to do this...
Could someone help me ?

Thanks
Gus.

call SortMyLog c:\folder\MyLog.log


@echo off
if {%1}=={} @echo Syntax: call SortMyLog LogFilePath&goto :EOF
if not exist %1 @echo Syntax: call SortMyLog LogFilePath - %1 does NOT exist.&goto :EOF
setlocal
set MyLog=%1
set wrk1="%TEMP%\SortMyLog_%RANDOM%.TM1"
set wrk2="%TEMP%\SortMyLog_%RANDOM%.TM2"
if exist %wrk% del /q %wrk%
for /f "Tokens=*" %%a in ('type %MyLog%') do (
for /f "Tokens=3 Delims=," %%d in ('@echo %%a') do (
@echo %%d;%%a>>%wrk1%
)
)
sort %wrk1% /O %wrk2%
del /q %MyLog%
for /f "Tokens=1* Delims=;" %%a in ('type %wrk2%') do (
@echo %%b>>%MyLog%
)
del /q %wrk1%
del /q %wrk2%
endlocal
 
Hi Jerold,

Thanks for the script. It's grat help.

It works perfectly.
But if I give another name than SortMyLog.bat to the file, an error message
appears. :
" Maximun setlocal recussion level reached"

I can't figure out why... Do you know ?

Did you by any chance try to call it SORT.BAT or SORT.CMD?
(if so, this conflicts with the SORT command in the Batch file)

Always avoid giving a Batch file any name that conflicts with an
internal or external command.
 
Back
Top