powershell - Matching string of pattern and size -
i want search text file 2 strings. output printed if first string greater 8 characters.
here command trying run:
get-content -path .\std_server*.out | select-string '((if "cpu=" -gt 8)|application=")' | out-file -width 1024 .\test.txt
so want search file std_server*.out both values cpu , application, want print these values if value cpu greater 8 characters.
how do that?
currently, have basic version works '(cpu=|application=")', prints out values of cpu, , want application printed out when cpu unreasonably high value (cpu > 8).
thanks in advance.
that nested logic if won't work have seen. need quantifier characters match after cpu=
in order define conditional match there. could measure match post processing might create more headache since have work around application="
matches well.
presumably file have string @ start of line , nothing else follows them? ensure correct matches idea use anchors.
also might use export-csv
right properties since select-string
return matches objects.
$pattern = '^(cpu=.{8,}|application=".*)$' get-content -path .\std_server*.out | select-string -path c:\temp\text.txt -pattern $pattern | select-object path,linenumber,line | export-csv -notypeinformation .\test.txt
cpu=.{8,}
match "cpu=" literally , @ least 8 characters have follow match. use anchors ensure start end of matches want , nothing more.
you first , last sentences conflict me possible whole match supposed 8 characters perhaps want number 4.
Comments
Post a Comment