Right concatenate a column in a csv file using powershell

Viewed 84

Lets say I have a csv with the following columns:

  A        B
   2     1000
  10     1000
 199     1000
9101     1000

I am looking to have column A right fill column B to have a result like the following:

 B
1002
1010
1199
9101

How can I achieve this output?

Thanks!

1 Answers

You could use Select-Object with a calculated property to "merge" the two into one:

# Import existing data
$data = Import-Csv path\to\data.csv 

# Create a new property B with the value of the existing A + B
$data = $data |Select @{Name = 'B'; Expression = { [int]$_.A + $_.B }}

# Export to a new CSV file
$data | Export-Csv path\to\new.csv
Related