I have two text files that I need to combine by concatenating line n from file #2 to line n of file #1 to make line n of file #3. They will always have the same number of l
You can use a For loop to do this in PowerShell:
$File1 = Get-Content C:\Path\To\File1.txt
$File2 = Get-Content C:\Path\To\File2.txt
$File3 = @()
For($a=0;$a -lt $File1.count;$a++){
$File3+=$File1[$a].trim()+$File2[$a].trim()
}
$File3 | Out-File C:\Path\To\NewFile.txt
Edit: Ok, I didn't think of single line files. That would make $File1 and/or $File2 strings instead of arrays. We can make them arrays easily enough so it can properly index into them:
$File1 = @((Get-Content C:\Path\To\File1.txt))
$File2 = @((Get-Content C:\Path\To\File2.txt))
$File3 = @()
For($a=0;$a -lt $File1.count;$a++){
$File3+=$File1[$a].trim()+$File2[$a].trim()
}
$File3 | Out-File C:\Path\To\NewFile.txt