我想将uid
值从一个文件复制到另一个文件。
如果test1.xml包含something something uid="123"
且test2.xml包含something something uid="11111"
test2.xml应为something something uid="123"
我该怎么做?
答案 0 :(得分:0)
$inputFile1 = "C:\ephemeral\file1.xml"
$inputFile2 = "C:\ephemeral\file2.xml"
$outputFile = "C:\ephemeral\file3.txt"
if ((Select-String -Pattern "uid=" -Path $inputFile1 |
select -last 1) -match ":(/>\d+):")
{
$insertPoint = $Matches[1]
Get-Content -Path $inputFile1 | select -First $insertPoint | Out-File $outputFile
Get-Content -Path $inputFile2 | Out-File $outputFile -Append
Get-Content -Path $inputFile1 | select -Skip $insertPoint | Out-File $outputFile -Append
}