CMD or Powershell command to combine (merge) corresponding lines from two files

前端 未结 6 1688
说谎
说谎 2020-11-29 12:56

Is it possible using CMD and Powershell to combine 2 files into 1 file like this:

file1-line1 tab file2-line1
file1-line2 tab file2-line2
file1-line3 tab file2-li         


        
6条回答
  •  天涯浪人
    2020-11-29 13:31

    In PowerShell, and assuming both files have exactly the same number of lines:

    $f1 = Get-Content file1
    $f2 = Get-Content file2
    
    for ($i = 0; $i -lt $f1.Length; ++$i) {
      $f1[$i] + "`t" + $f2[$i]
    }
    

提交回复
热议问题