在不修改输入文件的情况下编辑和合并 xml 个文件
Editing and merging xml files without modification of input files
我的任务是将两个 xml 文件合并在一起。在合并这两个文件之前,我需要删除第二个文件的第一行。通过编写这两行,我能够接收到所需的输出文件:
#case if both files exists - remove first line from the file
(Get-Content $JfilePath | Select-Object -Skip 1) | Set-Content $JfilePath
#mergeFiles together
Get-Content $MfilePath, $JfilePath | Set-Content $mergedFile
问题是我正在通过执行第一个 cmdlet 来修改第二个文件。我想保留这两个文件的原始形式。我也不想创建任何临时文件。
我正在尝试执行以下操作:
Get-Content $MfilePath, (Get-Content $JfilePath | Select-Object -Skip 1) | Set-Content $mergedFile
但我收到错误消息:
Get-Content : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'LiteralPath'. Specified method is not supported.
请问如何在不修改这些输入文件的情况下接收输出文件?
试试这个:
(Get-Content $MfilePath), (Get-Content $JfilePath | Select-Object -Skip 1) | Set-Content $mergedFile
我的任务是将两个 xml 文件合并在一起。在合并这两个文件之前,我需要删除第二个文件的第一行。通过编写这两行,我能够接收到所需的输出文件:
#case if both files exists - remove first line from the file
(Get-Content $JfilePath | Select-Object -Skip 1) | Set-Content $JfilePath
#mergeFiles together
Get-Content $MfilePath, $JfilePath | Set-Content $mergedFile
问题是我正在通过执行第一个 cmdlet 来修改第二个文件。我想保留这两个文件的原始形式。我也不想创建任何临时文件。 我正在尝试执行以下操作:
Get-Content $MfilePath, (Get-Content $JfilePath | Select-Object -Skip 1) | Set-Content $mergedFile
但我收到错误消息:
Get-Content : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'LiteralPath'. Specified method is not supported.
请问如何在不修改这些输入文件的情况下接收输出文件?
试试这个:
(Get-Content $MfilePath), (Get-Content $JfilePath | Select-Object -Skip 1) | Set-Content $mergedFile