Solved

question about replace

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
A procedure for exporting installed hotfix details of remote computers using powershell
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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