9

I have two text files with data.

First text file contains a big list of fullpaths to my files. d:\cat\cat1.txt

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

Second text file contains a short list of fullpath to my \files

d:\cat\file\cat2.txt

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

I need third file which contains

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

Thx for help.

Andy Arismendi
  • 50,577
  • 16
  • 107
  • 124
user1334176
  • 101
  • 1
  • 1
  • 2
  • 1
    Your going to need to explain the rule for sorting the output. We can only guess. – zdan Apr 15 '12 at 16:39

2 Answers2

15

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

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

It is not clear from your example what kind of "specific" combination you want, so you may want to explain that, but the logic for combining files will be like above.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • 3
    If you want to combine all text files in a path, try: gc C:\Path\*.txt | Out-file C:\Path\MergedTextFile.txt – The Woo Aug 11 '14 at 04:38
  • this is sllooooowwwwwwww - https://stackoverflow.com/questions/17749058/combine-multiple-text-files-into-one-text-file-using-python#17749339 – Wjdavis5 Aug 25 '18 at 19:49
4

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

Get-ChildItem d:\cat\cat1.txt,d:\cat\file\cat2.txt | 
  Get-Content | Out-File d:\cat\cat3.txt
Shay Levy
  • 121,444
  • 32
  • 184
  • 206