How do I concatenate two text files in PowerShell?

前端 未结 11 1983
没有蜡笔的小新
没有蜡笔的小新 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:33

    Since most of the other replies often get the formatting wrong (due to the piping), the safest thing to do is as follows:

    add-content $YourMasterFile -value (get-content $SomeAdditionalFile)
    

    I know you wanted to avoid reading the content of $SomeAdditionalFile into a variable, but in order to save for example your newline formatting i do not think there is proper way to do it without.

    A workaround would be to loop through your $SomeAdditionalFile line by line and piping that into your $YourMasterFile. However this is overly resource intensive.

提交回复
热议问题