powershelljointransposefile-manipulation

Is there a PowerShell equivalent of `paste` (i.e., horizontal file concatenation)?


I want to horizontally concatenate a bunch of CSV files using PowerShell. (When considering possible "duplicate" questions", please not that "a bunch" is not "two".) What is the PowerShell equivalent of the Linux paste command?


Solution

  • A few months ago, I submitted a proposal for including a Join-Object cmdlet to the standard PowerShell equipment #14994.

    Besides complexer joins based on a related property, the idea is to also be able to do a side-by-side join (by omiting the -On parameter).
    Taken this Paste command in Linux as an example:

    $State =
    'Arunachal Pradesh',
    'Assam',
    'Andhra Pradesh',
    'Bihar',
    'Chhattisgrah'
    
    $Capital =
    'Itanagar',
    'Dispur',
    'Hyderabad',
    'Patna',
    'Raipur'
    

    Installation

    Install-Module -Name JoinModule
    

    Creating a side-by-side array:

    1..5 |Join $State |Join $Capital |% { "$_" }
    
    1 Arunachal Pradesh Itanagar
    2 Assam Dispur
    3 Andhra Pradesh Hyderabad
    4 Bihar Patna
    5 Chhattisgrah Raipur
    

    Creating a side-by-side object:

    1..5 |Join $State |Join $Capital -Name Number, State, Capital
    
    Number State             Capital
    ------ -----             -------
         1 Arunachal Pradesh Itanagar
         2 Assam             Dispur
         3 Andhra Pradesh    Hyderabad
         4 Bihar             Patna
         5 Chhattisgrah      Raipur
    

    Concatenate ("Paste") two objects:

    $List = $State |Join $Capital -Name State, Capital
    $Id = ConvertFrom-Csv @'
    Id
    A
    B
    C
    D
    E
    '@
    
    $Id |Join $List
    
    Id State             Capital
    -- -----             -------
    A  Arunachal Pradesh Itanagar
    B  Assam             Dispur
    C  Andhra Pradesh    Hyderabad
    D  Bihar             Patna
    E  Chhattisgrah      Raipur
    

    References:

    Please give a 👍 if you support the proposal to Add a Join-Object cmdlet to the standard PowerShell equipment (#14994)