powershell - 从 PowerShell 输出中删除额外的空格
问题描述
我有一个 PowerShell 程序用输入文件中的另一个字符串替换一些字符串,但是与输入文件相比,输出文件有一个额外的空格/行。
$InputACKFile = 'C:\Testing_Newline\Aj*.dat'
Write-Host "Found " ($InputACKFile | Measure-Object).Count " files to process"
$InputACKFile = Get-ChildItem $InputACKFile
foreach ($xfile in $InputACKFile) {
Write-Host "Processing file: $xFile`r"
#((Get-Content $xfile).Replace("~", "`n")) | Out-File $xfile.FullName
[System.IO.File]::ReadAllText($xfile).Replace("~","`n") |
Set-Content $xfile
$flag = 0
(Get-Content $xfile | ForEach {
if ($_ -match "^PQ\*") {
$_ -replace "test1", "test2"
} elseif ($_ -match "^TA\*") {
$_ -replace "test1", "test2"
} elseif ($_ -match "^ABC\*RS\*") {
$_ = '';
$flag = 1
} elseif ($_ -match "^(DE\*)([0-9]+)(\*[0-9]+)$" -and $flag -eq 1) {
$_ -replace ($matches[2]), ([int]::Parse($matches[2])-1);
$flag = 0
} else{
$_
}
}) | Out-File $xfile.FullName -Encoding Ascii
((Get-Content $xfile) -join("~")) | Set-Content $xfile.FullName
}
解决方案
推荐阅读
- javascript - 如何使用javascript循环对象数组?
- javascript - 将 svg 转换为 react-native-svg
- sql-server - 什么是重复相同数字 5 次或更多次的正则表达式,例如 11111、22222、33333、44444
- javascript - 折射:从猫鼬回调中返回或推送值到新的数组值
- sonarqube - sonar-runner.bat JAVA_HOME 未指向有效的 Java 主目录
- python - jupyter notebook 没有在 anaconda 提示符中打开
- ruby-on-rails - 在三元运算符条件下带有 Link_to 助手的 Image_tag
- c++ - 重载运算符<<在谷歌C++风格
- sails.js - Sails.js 1.0 find 不会自动返回关联
- javascript - 通过服务器路径访问 json 对象时获取 xmlhttp 响应为空