query string - How can I get specified querystring key-value on custom log files with powershell? -


i've tried parse own custom log files rows , except spesific rows header value involved querystring values , included spesific key-value

i spesified example log file rows below :

2016-01-04 14:07:06 192.168.1.0 - example.com mainpage a=2&b=20&c=12-10&d=apple  2016-01-04 14:07:07 192.168.1.0 - example.com search x=2&y=20&c=56-32-12&d=orange  2016-01-04 14:07:08 192.168.1.0 - example.com prodview r=1&b=20&c=24&d=orange 2016-01-04 14:09:38 192.168.1.0 - example.com prodview a=2&b=20&c=1-23e&d=orange 

what want own powershell result

2016-01-04 14:07:08 192.168.1.0 - example.com prodview r=1&b=20&c=24&d=orange 

output must show querystring parameters contains c , points numeric value(it mustn't contains '-' character)

my own query below :

import-csv -encoding utf8 .\logs\x.log -header a,b,c,d,e,f,g,h -delimiter ' ' | {$_.h -match "c"} | select-string h 

but i've blocked when attempt parse querystring parameters

best regards

in example, have double , triple spaces, example works if there single space.

import-csv -encoding utf8 .\logs\x.log -header a,b,c,d,e,f,g,h -delimiter ' ' | ? h -match 'c[^-]+(&|$)' | select -exp h 

or maybe this:

gc .\logs\x.log | % {$($_ -replace ' +', ' ').trim().split(' ')[-1]} | ? {$_ -match 'c[^-]+(&|$)'} 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -