?
Solved

question about replace

Posted on 2016-07-28
2
Medium Priority
?
47 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

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