Reputation:
I am new to PowerShell, and I have the following example code and output to illustrate my problem:
select-string "$env:appdata\..\Local\test\*.ini" -pattern "example_adjustment=" | select filename, line | sort-object -property line -Descending >> file.txt
Filename Line
-------- ----
test1.ini example_adjustment="4.2"
test4.ini example_adjustment="11.0000000"
test2.ini example_adjustment="1.20"
test5.ini example_adjustment="0.90"
test3.ini example_adjustment="0.90"
I want to be able to modify the output so that the "Line" values appear as their numbers only and in float format for the purpose of the sort performing correctly. The end result is I'd be appending that information to a text file.
How would I go about modifying the Line property? I saw a post about regex, but I cannot edit directly from the pipe using regex it seems.
Upvotes: 0
Views: 44
Reputation: 174990
I cannot edit directly from the pipe using regex it seems.
You most certainly can! :-)
Use the -replace
regex operator inside a calculated property:
... |Select filename,@{Name='Line';Expression={$_.Line -replace 'example_adjustment="([^"]*)"','$1'}}
Upvotes: 1