How to rename a column heading in a CSV file?
csv, powershell
Solution
You may use `Select-Object` with a calculated property to do this:
Import-Csv test.csv |
Select-Object @{ expression={$_.first_name}; label='test' } |
Export-Csv -NoTypeInformation test1.csv
Problem
I cannot work out how to rename a column heading in a CSV file with Windows PowerShell. I can add new rows, delete rows, fill, and export, but cannot find out how to change a header value. I thought I could import the CSV & export with headers specified, but taht doesn't work: ``` import-csv c:\tmp\test.csv | Select-Object first_name | Export-Csv -header "test" c:\tmp\test1.csv ``` I basically need to re-format a CSV file, so if I can select the data I want & specify the new headers that would be perfect.