I have several log files which is named by the following pattern Log_yyyy_M_d.log
Log_2010_7_1.log
Log_2010_7_2.log
Log_2010_7_3.log
Log_2010_7_4.log
Log_2010_7_5.log
etc....
I want to merge all of them to a single file where the content is orded by date.
So I’ve come up with something like this:
for %f in (*.log) do type “%f” >> mergedlogs.txt
They are however not added to the mergedlogs.txt file ordered by date (asc). How may I accomplish that using standard shell/powershell scripts? I was hoping to avoid having to create a small .exe to solve this (in reality I guess that would have saved me a lot of time instead trying to do this in shell scripts).
One approach is to have merge syntax do a order by, but then I would have to rename the files to another pattern Log_yyyy_MM_dd.log
Can’t seem to get shell scripting to do a multiple rename by wildcards
dir *??.log and dir *_?.log should give me all the filenames which I need to rename, but this syntax is not giving me the desired result
ren *_?.log *_0?.log
This would be the desired rename result: Log_2010_12_1.log >> Log_2010_12_01.log
Any help with the shell rename script (or powershell) would be appreciated, or maybe another approach to achieve the main goal which is to merge all the log files to a single file where the content is order by filename-date.
Here is a script that iterates over logs , arranges them on parsed date, and merges into one: