Created
April 8, 2013 14:41
-
-
Save jkaflik/5337290 to your computer and use it in GitHub Desktop.
Easily merge .csv files which have an header
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
<?php | |
$options = array(); | |
$arguments = array(); | |
array_shift( $argv ); | |
foreach ( $argv as $arg ) | |
{ | |
if ( $arg[0] == '-' ) | |
{ | |
$options[] = substr( $arg, 1 ); | |
} | |
else | |
{ | |
$arguments[] = $arg; | |
} | |
} | |
$header = false; | |
foreach ( $arguments as $file ) | |
{ | |
$firstLine = true; | |
foreach ( file( $file ) as $line ) | |
{ | |
if ( $firstLine ) | |
{ | |
$firstLine = false; | |
if ( $header ) | |
{ | |
continue; | |
} | |
else | |
{ | |
$header = true; | |
} | |
} | |
echo $line; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment