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?
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'
Install-Module -Name JoinModule
1..5 |Join $State |Join $Capital |% { "$_" }
1 Arunachal Pradesh Itanagar
2 Assam Dispur
3 Andhra Pradesh Hyderabad
4 Bihar Patna
5 Chhattisgrah Raipur
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
$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:
Join-Object script
Join-Object Module
Please give a 👍 if you support the proposal to Add a Join-Object cmdlet to the standard PowerShell equipment (#14994
)