[尝试将文件从Windows传输到Unix Azure环境时,出现错误dos2unix格式错误
dos2unix -o /xyz/home/ABC_efg.txt无法执行dos2unix格式更改。
我试图运行PS脚本来修复它,但是似乎可以正常工作。
Get-ChildItem -File -Recurse *.txt | % { $x = get-content -raw -path $_.fullname; $x -replace "`r`n","`n" | set-content -NoNewline -path $_.fullname }
好吧,部分原因是您正在将字符串传递到Set-Content
,然后尝试使用该字符串来确定将文件保存在何处。尝试从以下位置更改最后一部分:
$x -replace "`r`n","`n" | set-content -NoNewline -path $_.fullname
对此:
set-content -NoNewline -path $_.fullname -value ($x -replace "`r`n","`n")
如果不按期望的那样更新格式,则可能需要对-Encoding
使用Set-Content
参数。我对编码不是很熟悉,所以我不确定。
[而不是使用-replace
,我希望将内容读取为字符串数组,并将这些字符串与“`n”联接。像这样的东西:
$files = Get-ChildItem -File -Recurse -Filter '*.txt' | Select-Object FullName
$files | ForEach-Object {
(Get-Content -Path $_) -join "`n" | Set-Content -Path $_ -NoNewline
}