Skip to content

Instantly share code, notes, and snippets.

@jkaflik
Created April 8, 2013 14:41
Show Gist options
  • Save jkaflik/5337290 to your computer and use it in GitHub Desktop.
Save jkaflik/5337290 to your computer and use it in GitHub Desktop.
Easily merge .csv files which have an header
<?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