Skip to content

Instantly share code, notes, and snippets.

@Aergonus
Last active April 8, 2016 16:52
Show Gist options
  • Save Aergonus/3f9153c038ec362be72f12eb70c4329a to your computer and use it in GitHub Desktop.
Save Aergonus/3f9153c038ec362be72f12eb70c4329a to your computer and use it in GitHub Desktop.
Powershell CSV Concatenator
#Simple executeable solution for CSVs (Does not include header)
#foreach ($file in Get-ChildItem -path ".\" -filter "*.csv") {gc $file | select -Skip 1 | UNICORNS.csv}
$path = Read-Host 'Enter the path to the folder containing the CSV files (Ex: ".\" is the current directory)'
if(!$path) {$path = ".\"}
$match = Read-Host 'Enter REGEX Match filter (Ex: *.csv)'
if(!$match) {$match = "*.csv"}
$name = Read-Host 'Enter Name of Outputfile (I would suggest naming it UNICORNS.csv)'
# Get all the files before creating output
$files = Get-ChildItem -path $path -filter $match
# Check if output is defined
if (!$name){
if ($match -like '*csv*') {
# Get headers for the csv
gc $match | select -first 1
# Get content, skip header, and append to output file
foreach ($file in $files) {gc $file | select -Skip 1}
} else {
foreach ($file in $files) {gc $file}
}
} else {
if ($match -like '*csv*') {
# Get headers for the csv
gc $match | select -first 1 | sc $name
# Get content, skip header, and append to output file
foreach ($file in $files) {gc $file | select -Skip 1 | ac $name}
} else {
foreach ($file in $files) {gc $file | ac $name}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment