Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine two text files with powershell

Tags:

powershell

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.

like image 380
user1334176 Avatar asked Apr 15 '12 07:04

user1334176


2 Answers

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.

like image 55
manojlds Avatar answered Nov 05 '22 06:11

manojlds


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
like image 39
Shay Levy Avatar answered Nov 05 '22 05:11

Shay Levy