Solved

replace block text

Posted on 2016-07-31
4
33 Views
Last Modified: 2016-08-04
Hello,

In a text file, I want to replace :

AS
BEGIN

with

NOT FOR REPLICATION
AS
BEGIN

How can I do it?

Thanks

Regards
0
Comment
Question by:bibi92
  • 2
  • 2
4 Comments
 
LVL 83

Expert Comment

by:oBdA
ID: 41737044
Assuming PS 3.0 or later, because of the "Get-Content -Raw":
$Sql = Get-Content -Path 'C:\Temp\test.sql' -Raw
$Sql -replace '(?s)AS\r\nBEGIN', ("NOT FOR REPLICATION`r`nAS`r`nBEGIN") | Set-Content -Path "C:\Temp\test-NFR.sql"

Open in new window

0
 

Author Comment

by:bibi92
ID: 41737045
Thanks but we use powershell 2.0
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41737048
You should seriously consider upgrading to at least PS 3.0, which adds lots of nice features and fixes errors. PS 2.0 is from 2009, PS 5.0 is now available for Windows 7 /Server 2008 R2 and later.
$Sql = [IO.File]::ReadAllText("C:\Temp\test.sql")
$Sql -replace '(?s)AS\r\nBEGIN', ("NOT FOR REPLICATION`r`nAS`r`nBEGIN") | Set-Content -Path "C:\Temp\test-NFR.sql" 

Open in new window

0
 

Author Closing Comment

by:bibi92
ID: 41742548
thanks regards
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now