Splitting CSV files

I had to split a CSV with 14k entries into several files because the import crashed on one of our servers when I imported everything at once.

# split -l lines file_to_split output/
$ split -l 4000 export.csv export/venues
$ ls venues
venuesaa venuesab venuesac venuesad
$ cd export

# append .csv extension to every file
$ for i in *; do mv "$i" "$i.csv"; done
$ ls
venuesaa.csv venuesab.csv venuesac.csv venuesad.csv

# get header of the first file
$ header=$(head -n 1 venuesaa.csv)

# prepend header to every other file
$ ls | grep -v venuesaa | xargs echo -e "$header\n$(cat {})" > {}