作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用以下命令将目录的内容输出到 txt 文件:
$SearchPath="c:\searchpath"
$Outpath="c:\outpath"
Get-ChildItem "$SearchPath" -Recurse | where {!$_.psiscontainer} | Format-Wide -Column 1'
| Out-File "$OutPath\Contents.txt" -Encoding ASCII -Width 200
c:\searchpath\directory
name of file.txt
name of another file.txt
c:\searchpath\another directory
name of some file.txt
c:\searchpath\directory
nameoffile.txt
c:\searchpath\another directory
another file.txt
$configFiles=get-childitem "c:\outpath\*.txt" -rec
foreach ($file in $configFiles)
{
(Get-Content $file.PSPath) |
Foreach-Object {$_ -replace "'n", ""} |
Set-Content $file.PSPath
}
Select-String -Pattern "\w" -Path 'c:\outpath\contents.txt' | foreach {$_.line}'
| Set-Content -Path c:\outpath\contents2.txt
t to replace the tabs, it works perfect. But
r 和
n do not work. It's almost as though it doesn't recognize them as escape characters. But if I add
r 和 `n 在 txt 文件中然后运行脚本,它仍然没有替换任何东西。似乎不知道如何处理它。
最佳答案
Set-Content
默认添加换行符。更换 Set-Content
来自 Out-File
在你最后一次尝试你的问题时会给你你想要的文件:
Select-String -Pattern "\w" -Path 'c:\outpath\contents.txt' | foreach {$_.line} |
Out-File -FilePath c:\outpath\contents2.txt
关于powershell - 如何使用 Powershell 从文本文件中删除回车符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10759251/
我是一名优秀的程序员,十分优秀!