使用 PowerShell 连接文件 [英] Concatenate files using PowerShell
本文介绍了使用 PowerShell 连接文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是 PowerShell 3.
I am using PowerShell 3.
连接文件的最佳做法是什么?
What is best practice for concatenating files?
file1.txt + file2.txt = file3.txt
PowerShell 是否提供了直接执行此操作的工具?还是我需要将每个文件的内容加载到局部变量中?
Does PowerShell provide a facility for performing this operation directly? Or do I need each file's contents be loaded into local variables?
推荐答案
如果所有文件都在同一个目录下并且可以通过简单的模式匹配,下面的代码会将所有文件合二为一.
If all the files exist in the same directory and can be matched by a simple pattern, the following code will combine all files into one.
Get-Content .\File?.txt | Out-File .\Combined.txt
这篇关于使用 PowerShell 连接文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文