我正在整合两个通过CSV文件相互通信的软件,但是App A的输出文件需要进行一些后期处理才能让App B拿起它.
下面的代码将数据附加到以"C"开头的行,同时丢弃现在的其他三种可能性,因为这些部分将在以后添加.
$ _> null是我提出的,因为我找不到会删除IF语句中的行的代码片段.它似乎有效,但我想确定它是否正确.TIA
$original = "input.txt"
$destination = "output.txt"
$tempfile = [IO.Path]::GetTempFileName()
get-content $original | foreach-object {
if ($_ -match "^C,") {
$_ + ",append this" >> $tempfile
}
elseif ($_ -match "^J,") {
$_ > null
}
elseif ($_ -match "^B,") {
$_ > null
}
elseif ($_ -match "^O,") {
$_ > null
}
else {
$_ >> $tempfile
}
}
copy-item $tempfile $destination
remove-item $tempfile
Run Code Online (Sandbox Code Playgroud)