I need to concatenate some relatively large text files, and would prefer to do this via the command line. Unfortunately I only have Windows, and cannot install new software.
In powershell:
Get-Content file1.txt | Out-File out.txt
Get-Content file2.txt | Select-Object -Skip 1 | Out-File -Append out.txt
Here's how to do this:
(type file1.txt && more +1 file2.txt) > out.txt
I don't have enough reputation points to comment on the recommendation to use *.csv >> ConcatenatedFile.csv
, but I can add a warning:
If you create ConcatenatedFile.csv
file in the same directory that you are using for concatenation it will be added to itself.
more +2 file2.txt > temp
type temp file1.txt > out.txt
or you can use copy
. See copy /?
for more.
copy /b temp+file1.txt out.txt
I use this, and it works well for me:
TYPE \\Server\Share\Folder\*.csv >> C:\Folder\ConcatenatedFile.csv
Of course, before every run, you have to DELETE C:\Folder\ConcatenatedFile.csv
The only issue is that if all files have headers, then it will be repeated in all files.
This takes Test.txt
with headers and appends Test1.txt
and Test2.txt
and writes results to Testresult.txt
file after stripping headers from second and third files respectively:
type C:\Test.txt > C:\Testresult.txt && more +1 C:\Test1.txt >> C:\Testresult.txt && more +1 C:\Test2.txt >> C:\Testresult.txt