How do I concatenate two text files in PowerShell?

前端 未结 11 1968
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 03:17

I am trying to replicate the functionality of the cat command in Unix.

I would like to avoid solutions where I explicitly read both files into variables

11条回答
  •  囚心锁ツ
    2020-11-28 03:49

    To concat files in command prompt it would be

    type file1.txt file2.txt file3.txt > files.txt
    

    PowerShell converts the type command to Get-Content, which means you will get an error when using the type command in PowerShell because the Get-Content command requires a comma separating the files. The same command in PowerShell would be

    Get-Content file1.txt,file2.txt,file3.txt | Set-Content files.txt
    

提交回复
热议问题