powershell - Parse date from text file and extract lines where the date is greater than X -


i have client uses third-party software store confidential medical information. need find out users have opened particular record in database. have been in touch vendor, , way log in text file on each individual computer(apparently). need parse text file each computer pull out information need. here anonymous sample of information in text file - have added spaces between each line readability.

log in.|10/03/2012|01:12:45|dr john smith|3|fs01|windows 7 domain controller terminal services service pack 1 (6.1 build 7601)|3.12.1

progress note - new record opened|10/03/2012|01:13:33|dr john smith|666241|8463|richard test^05/09/1956|.f.|.t.|1|fs01

progress note - discarded user|10/03/2012|01:14:29|dr john smith|666241|8463|richard test|.f.|.t.|fs01

i can pull out line record name in question i.e. "richard test", these logs go way 2012. have idea how can parse date each line can pull after 01/01/2016 example?

import-module activedirectory $computers = "fs01"#get-adcomputer -filter * | select-object -expandproperty name  foreach($computer in $computers){  $path = "\\$computer\c$\users\public\documents\hcn\md\mdtrace.log" if(test-connection -computername $computer -count 1 -erroraction silentlycontinue){ if(test-path $path){ get-content -path $path | foreach { if($_ -match "thomas hogan"){write-output "$computer -- $_"} } } } } 

use regular expression extract date, like:

$cutoff = get-date -year 2013 -month 1 -day 1 get-content .\log.txt | ? {     $g = [regex]::match($_, '(\d\d)/(\d\d)/(\d\d\d\d)').groups     (get-date -year $g[3].value -month $g[2].value -day $g[1].value) -gt $cutoff  } | out-file filtered_log.txt 

if files large approach might faster:

$cutoff = get-date -year 2013 -month 1 -day 1 get-content .\log.txt -readcount 1 | % {     $_ | ? {         $g = [regex]::match($_, '(\d\d)/(\d\d)/(\d\d\d\d)').groups          (get-date -year $g[3].value -month $g[2].value -day $g[1].value) -gt $cutoff      } | out-file filtered_log.txt -append } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -