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.

1
  • 1
    Your going to need to explain the rule for sorting the output. We can only guess. Commented Apr 15, 2012 at 16:39

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

If you want to combine all text files in a path, try: gc C:\Path*.txt | Out-file C:\Path\MergedTextFile.txt
this is sllooooowwwwwwww - stackoverflow.com/questions/17749058/…
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

2 Comments

Why is it - when I have only 3 short files and I replace Get-ChildItem with Get-ChildItem -Recurse -Filter *.txt it actually adds those file in an endless loop?
@MauriceKlimek I'm getting the endless loop issue as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.