Powershell-一个简单的问题。
我想串联N个文本文件并将文件名放在每行的前面。怎么做却有完整的路径和文件名?每个文件应按原样保留所有文本和行终止符。
data1.txt
this is the text in
data1 file - hello
data2.txt
four score and
seven years ago
获取此文件
output.txt
data1.txt: this is the text in
data1.txt: data1 file - hello
data2.txt: four score and
data2.txt: seven years ago
将会是这样-但这确实有效。
get-content c:\ temp \ data * .txt | foreach-object {$ tmp = get-content $; $。basename +“,” + $ tmp}> output.txt
谢谢
最佳答案
尝试这样的事情:
$path = "c:\temp"
$out = "c:\temp\output.txt"
Get-ChildItem $path -Filter data*.txt | % {
$file = $_.Name
Get-Content $_.FullName | % {
"${file}: $_" | Out-File -Append $out
}
}
关于powershell - powershell-连接N个文本文件,并在每行前添加文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18724617/