Grab a string between characters


i have text file creating dump of data. this:

testdata=100 (someotherdata 100) (data=100)

testdata=101 (someotherdata 101) (data=101)

testdata=101 (someotherdata 101) (data=101)

there hundreds of these lines. need extract first number each line after "testdata=" variable can add numbers up. need getting numbers. summing easy. here's have far.

i have variable "$a" has data above. run:

[void]($a -match '^testdata=([^ (]+)')

there space between ^ , ( dont space in match. works if have 1 line in variable "$a". if have multiple lines doesnt work. can me figure why not working or tell me easier way accomplish need?

thanks


chris morgan


here's one-liner can point @ log file:

get-content .\mylog.log | { $_ -match '^testdata=(\d+) ' }| foreach { [int] $matches[1] } | measure -sum

thanks,
-lincoln



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file