Skip to content

Instantly share code, notes, and snippets.

@antoniocosentino
Created November 25, 2023 15:53
Show Gist options
  • Save antoniocosentino/11beca9c6fe45328b025a59f917e2cef to your computer and use it in GitHub Desktop.
Save antoniocosentino/11beca9c6fe45328b025a59f917e2cef to your computer and use it in GitHub Desktop.
Splitting a CSV file into multiple files (using Mac Terminal)
# to split the file
split -l 100000 -d filename.csv file_
# to add the csv extension to each of the files
for i in $(find file_*); do mv $i "$i.csv"; done
# to put the header from the first file into each of the other files
for i in $(find . -type f -name "file_*.csv" -not -name "file_00.csv");
do echo -e "$(head -1 file_00.csv)\n$(cat $i)" > $i;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment