Combine two text files with powershell

I have two text data files.

The first text file contains a long list of full paths to my files. d: \ cat \ cat1.txt

d:\test\file1-1.txt d:\test\file1-2.txt .... d:\test\file1-N.txt 

The second text file contains a short list fullpath for my \ files

d: \ cat \ file \ cat2.txt

 d:\test\file2-1.txt d:\test\file2-2.txt 

I need a third file containing

 d:\test\file1-1.txt d:\test\file1-2.txt d:\test\file2-1.txt d:\test\file1-3.txt d:\test\file1-4.txt d:\test\file2-2.txt d:\test\file1-5.txt d:\test\file1-6.txt d:\test\file2-1.txt 

Thanks for reference.

+7
source share
2 answers

If you want to combine several files (2 or more), you can do:

 gc d:\cat\cat1.txt,d:\cat\file\cat2.txt | out-file d:\cat\combinedcat.txt 

From your example, it is not clear which β€œspecific” combination you need, so you can explain it, but the logic for combining files will look higher.

+13
source

Get the contents of both files and save the output to a new file:

 Get-ChildItem d:\cat\cat1.txt,d:\cat\file\cat2.txt | Get-Content | Out-File d:\cat\cat3.txt 
+4
source

All Articles