I have few SQL script files and I am trying to remove the “GO” keyword from the files. unfortunately, there are many other words matching the search criteria and I do not want to replace them.
I want to replace the “GO” word only in those lines wherein the line does not have any other words except “GO”. I am able to find the line numbers where I have to do the changes but not sure how to make the changes in files.
$FILEFOLDER =gc “c:\test.sql”
$linenumber= $FILEFOLDER | select-string “GO”
foreach($line in $linenumber) {
$linenumbers=$line.LineNumber
$test1=$line.Line.Trim()
$len=$test1.length
if($len -eq 2)
{
$contentUpdate = $FILEFOLDER[$linenumbers] -replace “GO=”,“GO=$output”
Set-Content $NEWPATH $contentUpdate
}
}