Solved

question about replace

Posted on 2016-07-28
2
30 Views
Last Modified: 2016-07-28
I search to replace in file D:\MSSQL\scripts\sql\ddl\mv_ddl.sql :


CREATE TABLE [dbo].[Groups](
      [id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
      [name] [varchar](max) COLLATE French_CI_AS NOT NULL,
 CONSTRAINT [PK_Groups] PRIMARY KEY CLUSTERED
(
      [id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


CREATE TABLE [dbo].[Groups](
      [id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
      [name] [varchar](max) COLLATE French_CI_AS NOT NULL,
 CONSTRAINT [PK_Groups] PRIMARY KEY CLUSTERED
(
      [id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [FG_TEST]
) ON [FG_TEST] TEXTIMAGE_ON [LOB]


I execute

  $scrp.Options.FileName = "D:\MSSQL\scripts\sql\ddl\mv_ddl.sql"
  (Get-Content $scrp.Options.FileName) -replace 'ALLOW_PAGE_LOCKS  = ON\) ON\[PRIMARY\]', "ALLOW_PAGE_LOCKS  = ON\) ON [FG_TEST]" -replace '\) ON\[PRIMARY\]', "[FG_TEST] TEXTIMAGE_ON [LOB]" | Out-File $scrp.Options.FileName

but the result is

CREATE TABLE [dbo].[Groups](
      [id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
      [name] [varchar](max) COLLATE French_CI_AS NOT NULL,
 CONSTRAINT [PK_Groups] PRIMARY KEY CLUSTERED
(
      [id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [FG_TEST]
) ON [FG_TEST]

How can I resolve it?

Thanks

Regards
0
Comment
Question by:bibi92
2 Comments
 
LVL 12

Accepted Solution

by:
Dustin Saunders earned 500 total points
ID: 41733043
Try doing it this way, should work for you.
$file = "C:\test\mv_ddl.sql"

(Get-Content $file) | ForEach-Object {$_ -replace [regex]::Escape("ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]"), "ALLOW_PAGE_LOCKS  = ON) ON [FG_TEST]" -replace [regex]::Escape(") ON [PRIMARY]"), ") ON [FG_TEST] TEXTIMAGE_ON [LOB]"} | Set-Content $file

Open in new window

0
 

Author Closing Comment

by:bibi92
ID: 41733268
thanks
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

23 Experts available now in Live!

Get 1:1 Help Now