Solved

question about replace

Posted on 2016-07-28
2
25 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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…

705 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

17 Experts available now in Live!

Get 1:1 Help Now