I need to search for a string in a TEXT file (for Example “policy_member”) and extract the content between strings. I need to do it recursively till end of the text content.
I could use:
Get-Content C:\input.txt
but I am not sure how to proceed.
I had written something similar in another language (as below) and was hoping I could write something similar with Powershell.
PowerShell doesn’t have the same string manipulation capabilities as some other scripting languages. You probably want to look into Regular Expressions; with a “capturing” expression, PowerShell’s -match operator will generate a $matches collection that contains captures substrings. You can also look into Select-String to see if it meets your needs.
Thanks Don. I already tried $matches but it will not help in this case.
I need to find “policy_name” and then get the corresponding “”.
There are several “policy_names” and several "policy_member"s for the “policy_name”
With this command it only gives me the “policy_name”:
I could search for the string , but then I will not know the corresponding “policy_member”
Thats the reason I need something like a while/for loop and get for the POSITION of the “policy_name” when I find it. Then use the POSITION to determine the start of the following “policy_member”