gpt4 book ai didi

performance - 修改大型.xml文件时PowerShell服务器崩溃

转载 作者:行者123 更新时间:2023-12-02 23:41:41 26 4
gpt4 key购买 nike

正如标题所述,我制作了一个PowerShell脚本,其性能如此之差,以至于它过度扩展了服务器资源并使之崩溃。

该脚本读取了一个whole.xml文件,并在文件的开头和结尾处添加了文本。它还将文件名更改为我的filename.txt中的文件名。

.xml文件大约有500 MB,并且有470万行。有没有一种方法,我不必读取整个文件,而不必读取松散的信息?

function start-jobhere([scriptblock]$block){
start-job -argumentlist (get-location),$block { set-location $args[0]; invoke-expression $args[1] }
}

$handler_button1_Click= {
Try{
$job3 = start-jobhere {
#Text that should be at filebeginning
@('<?xml version="1.0" encoding="UTF-8"?>
<ids:ControlInfo>
<ids:ObjectFormat>CSV</ids:ObjectFormat>
<ids:SeparatorForCSV>;</ids:SeparatorForCSV>
</ids:ControlInfo>

<ids:BatchDeltaUntil></ids:BatchDeltaUntil>
</ids:BatchInfo>
</ids:Header>
<ids:Body>'
) + (get-content ZUB_Lokalisation.xml) | set-content ZUB_Lokalisation.xml

#Text that should be at file end
Add-Content ZUB_Lokalisation.xml -Value "</ids:Body>`n</ids:SimpleOperation>"

#Information that goes into the header of the file but has to be extracted from the filename inside a .txt
$filename = Select-String filename.txt -Pattern "Lokalisation"
$nameoffile = [System.IO.Path]::GetFileName($filename)
$split = $nameoffile.split('_')
$finalid = $split[5]
$content = Get-Content ZUB_Lokalisation.xml
$content[8] = ' <ids:BatchInfo ids:BatchID="{0}">' -f $finalid
$content | Set-Content ZUB_Lokalisation.xml

#Rename the file
Rename-Item ZUB_Lokalisation.xml -NewName $filename}
}catch [System.Exception]{zeigen
[System.Windows.Forms.MessageBox]::Show("ZUB_LOK_ERROR", "ERROR")}
}

Get-Job | Wait-Job | Where State -eq "Running"
}

最佳答案

创建包含所需的开始和结束片段的文件。

然后在dos窗口或批处理文件中运行此命令:

COPY StartFile.TXT + YourXMLFile.TXT + EndFile.TXT OutputFile.TXT

这会将三个文件粘贴在一起,并将它们另存为OutputFile.TXT

关于performance - 修改大型.xml文件时PowerShell服务器崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40424797/

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