Solved

question about replace

Posted on 2016-07-28
2
41 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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