Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell - Extract data contained between two characters

$
0
0

Hello, I am looking for Powershell assistance with extracting text contained between known words.

I have the script below which works for letters/number, however I need to be able search for [Section1] and [Section2].  The script below doesn't work with the square brackets (assuming characters might be reserved or ignored in some way)?  Can anyone help?

$flag=0
Get-Content c:\in.txt |
foreach {
Switch -Wildcard ($_){
"*SECTION1*" {$flag=1}
"*SECTION2*" {$flag=0}
}
if ($flag -eq 1){
Out-File C:\out.txt -InputObject $_ -Append
}
}



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>