jt30605
asked on
PowerShell to pull value between two characters in a text file.
I need to pull the value that is between two characters in a text file. For example, the contents of my text file are:
test parse.
I want to pull the value
between the pounds. The value is #456#.
How can I grab the "456" value? As close as I've gotten is using the select-string statemnt I can get the entire line that includes the value, but I cannot get just that value.
My select-string statement is $str = Select-String -Pattern "#(.*)#" c:\testparse.text
Any help would be greatly appreciated.
test parse.
I want to pull the value
between the pounds. The value is #456#.
How can I grab the "456" value? As close as I've gotten is using the select-string statemnt I can get the entire line that includes the value, but I cannot get just that value.
My select-string statement is $str = Select-String -Pattern "#(.*)#" c:\testparse.text
Any help would be greatly appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have used these 5 steps for my script, a problem I am getting is it is stopping on the first result, and not going through the entire file. Seems it's not looping
$messagesubjects=import-cs
foreach($messagesubject in $messagesubjects) {
$start= $messagesubject.indexof("#
$end= $messagesubject.indexof("#
$length =$end - $start
$messagesubjects.substring
}