Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8309823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:14:25+00:00 2026-06-08T19:14:25+00:00

I have several log files which is named by the following pattern Log_yyyy_M_d.log Log_2010_7_1.log

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:14:27+00:00Added an answer on June 8, 2026 at 7:14 pm

    Here is a script that iterates over logs , arranges them on parsed date, and merges into one:

    dir Log_*.log | % { #get all logs files
        #parse name to extract date
        $match = [regex]::Match($_.Name, "(\d+)_(\d+)_(\d+)");
    
        #add property with extracted date in invariant culture
        Add-Member -InputObject $_ -MemberType NoteProperty -Name ParsedDate `
                                    -Value ([DateTime]::Parse([string]::Format("{0}/{1}/{2}", `
                                                $match.Groups[1], $match.Groups[2], $match.Groups[3]), `
                                        [System.Globalization.CultureInfo]::InvariantCulture));
    
        return $_;
    } | `
      Sort-Object -Property ParsedDate | gc -Encoding utf8 >> merged.logs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem which requires me to parse several log files from a
I have several batch files which set a log file path and start visual
I have several threads which need to write to two different text files. So
I have a log table which have several child tables inherit it 。but my
I have a folder /mnt/sdcard/Bluetooth which contains several zip files. Each of this zip-files
I have several xml files with different node structure. I want to extract xml
I have several xml files that are formated this way: <ROOT> <OBJECT> <identity> <id>123</id>
we have several tens of macro enabled excel files, each of those contains few
I have several Select which depend on each other if I select a value
I have several question: If there is an error which has to be displayed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.