Last active
January 7, 2016 06:36
-
-
Save midnightfreddie/e34c2e47824a08e5698d to your computer and use it in GitHub Desktop.
Reply to https://www.reddit.com/r/PowerShell/comments/3wfrj4/load_multiple_inputs_or_arrays_into_a_single/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$data = @{} | |
Import-Csv namecity.csv | | |
ForEach-Object { | |
if (-not $data[$_.name]) { $data[$_.name] = @{} } | |
$data[$_.name]["city"] = $_.city | |
} | |
Import-Csv namestate.csv | | |
ForEach-Object { | |
if (-not $data[$_.name]) { $data[$_.name] = @{} } | |
$data[$_.name]["state"] = $_.state | |
} | |
Import-Csv namecountry.csv | | |
ForEach-Object { | |
if (-not $data[$_.name]) { $data[$_.name] = @{} } | |
$data[$_.name]["country"] = $_.country | |
} | |
# Make use of this object format, or... | |
# Flatten data into tabular format | |
$data.Keys | ForEach-Object { | |
$Properties = [ordered]@{ | |
name = $_ | |
city = $data[$_].city | |
state = $data[$_].state | |
country = $data[$_].country | |
} | |
New-Object psobject -Property $Properties | |
} # Pipe here to Export-Csv, ConvertTo-Html or just emit objects or whatever |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name | city | |
---|---|---|
Name1 | City1 | |
Name2 | City2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name | country | |
---|---|---|
Name1 | Country1 | |
Name4 | Country2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name | state | |
---|---|---|
Name1 | State1 | |
Name3 | State2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment