Created
November 25, 2023 15:53
-
-
Save antoniocosentino/11beca9c6fe45328b025a59f917e2cef to your computer and use it in GitHub Desktop.
Splitting a CSV file into multiple files (using Mac Terminal)
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
# 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