gpt4 book ai didi

powershell - 只读取文件中的一部分

转载 作者:行者123 更新时间:2023-12-02 15:31:40 25 4
gpt4 key购买 nike

我想从我的文件中排除特定内容。例如我的示例代码:

GO
CREATE TABLE [dbo].[Employee] (
[EmployeeID] INT NULL,
[Name] VARCHAR (50) NULL
);


GO
CREATE TABLE #tempAP_Data_new (
planeID INT ,
APNM INT,
)

DECLARE
@APNM [VARCHAR] (100) ,
@MajorModel [VARCHAR] (100) ,
@MinorModel [VARCHAR] (100) ,

CREATE TABLE #tempnew_Data(
planeNum INT ,
APNMID INT,
)
GO

在此,我只需要 CREATE TABLE 语句,而不是 CREATE TABLE #。输出应该是:

CREATE TABLE [dbo].[Employee] (
[EmployeeID] INT NULL,
[Name] VARCHAR(50)NULL
);

我的代码是:

$searchCreateTable = "CREATE TABLE" 
$alterTable = (Get-Content $path\$deltaFile -Delimiter 'GO') -match "(?m)^$searchCreateTable*"

最佳答案

如果语句始终在前 5 行内,则可以使用 -Head 参数:

Get-Content $path\$deltaFile -Head 5

否则您可以拆分文件:

(Get-Content $path\$deltaFile -raw) -split 'Go' | select -Index 1

关于powershell - 只读取文件中的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39034675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com