I\'m trying to write a script to search the contents of a file, and when it comes across a grouping of ASCII control characters, to insert a CR/LF.
The pattern of ch
I have a function in a script that does something like this. Not sure if this will help you:
# This function will make a new file that has custom comments
# it will comment out "rollback tran"
# it will uncomment out "--commit tran"
function CommentAndUncomment($TheScript)
{
PrintTextAndTime("About to run this SQL file: $TheScript")
PrintTextAndTime("Will comment out 'rollback tran' and uncomment '--commit tran'")
$content = Get-Content $TheScript
$content |
ForEach-Object {
if ($_ -clike "*ROLLBACK TRAN;*") {
$_ -replace "ROLLBACK TRAN;", "--ROLLBACK TRAN;"
}
elseif ($_ -clike "*--COMMIT TRAN;*") {
$_ -replace "--COMMIT TRAN;", "COMMIT TRAN;"
}
else{
$_
}
} |
Set-Content $ModifiedCommentsFile
echo $ModifiedCommentsFile
sqlcmd -i $ModifiedCommentsFile
del $ModifiedCommentsFile
}