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 6918229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:49:55+00:00 2026-05-27T09:49:55+00:00

I’m trying to extract a set of data from some (large) text files. Basically,

  • 0

I’m trying to extract a set of data from some (large) text files. Basically, each line looks something like this:

2011-12-09 18:20:55, ABC.EXE[3b78], The rest of the line...

I’d like to get the date and the bit between the braces (the process id), and then compile a table. The second stage of the task is to group this table so that I get the earliest date for each process id, in effect giving me the date and time of the first log entry per process id which will hopefully approximate to the start time of that instance of the process.

What I’ve got so far (split onto different line for readability)

gci -filter *.log -r 
 | select-string '(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}), ABC.EXE\[(.{4})' 
 | % { $_.matches } | % { $_.groups } | % { $_.value }

spits out the the captures. I’d like to ignore the first capture, and combine the second and third onto the same line.

Help?
Please?

Edit: DOH! Can’t answer my own question. So…

Ok, I think I’m on the right track. A SO question here helped me to get the individual parts I wanted, namely:

$_.matches[0].groups[1].value, $_.matches[0].groups[2].value

Then, an MSDN article here shows how to ‘clump’ the bits into an object, which allows it to be grouped / sorted / manipulated. Final result

gci -filter *.log | select-string '(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}), ABC.EXE\[(.{4})' 
 | % { new-object object 
  | add-member NoteProperty Name $_.matches[0].groups[1].value -passthru 
  | add-member NoteProperty PId $_.matches[0].groups[2].value -passthru }

Quite messy, so if anyone knows of a cleaner way to do it, please let me know.

  • 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-05-27T09:49:55+00:00Added an answer on May 27, 2026 at 9:49 am

    You can create new objects simpler in PowerShell v2 where the New-Object cmdlet supports a -Property parameter that receives a hashtable of properties:

    New-Object PSObject -Property @{
        Name = $_.matches[0].groups[1].value
        PId = $_.matches[0].groups[2].value
    }
    

    Generally, I’d do the processing a little differently, though:

    # prepare table
    $data = $(switch -Regex -File filename {
        '^[^,]+' { $date = [datetime]$Matches[0] }
        '(?<=\[)[^\]]+' { $id = $Matches[0] }
        '$' { New-Object PSObject -Property @{
            Date = $date
            PId = $id
        } }
    })
    

    Using switch -regex has become a nice way (to me at least) to do quick-and-dirty parsers for text data. With -Regex all matching cases will be run, in this case all (so it’s just a convenience to separate different parts of the matching). The first one grabs the date and time and stores it in a variable (even as a DateTime value); the second gets the process ID and the third, matching on the end of a line, puts it all together.

    Just a personal preference, though; I have actually never used Select-String.

    $data |
        group PId |
        foreach { New-Object PSObject -Property @{
            PId = $_.Name
            MinDate = @($_.Group | sort Date)[0].Date
        } }
    

    This then uses the just-compiled data, groups it by process ID and outputs the ID with the minimum date for each one.

    Note, this is more a “looks nice in code” approach. If the files you’re dealing with are really large, you probably want something way more efficient.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am currently running into a problem where an element is coming back from

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.