Created
October 16, 2019 16:19
-
-
Save ersatzryan/0079ed96bbaf8018b42bc0458cbb8deb to your computer and use it in GitHub Desktop.
CSV Splitter
This file contains 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
#!/bin/bash | |
NUMLINES=4000 | |
while [[ $# -gt 0 ]]; do | |
case "$1" in | |
-l|--lines) NUMLINES="$2"; shift; shift;; | |
-h|--help ) echo -e "Usage: csvsplit [-l line_count] file\n -l, --lines: Number of lines to split\n -h, --help: Show this message"; exit 1;; | |
-* ) echo "Unknown option: $1"; exit 1;; | |
-- ) shift; break;; | |
* ) FILE="$1"; shift;; | |
esac | |
done | |
FILENAME=$(basename $FILE .csv) | |
tail -n +2 $FILE | split -l $NUMLINES - split_ | |
for split in split_* | |
do | |
head -n 1 $FILE > tmp_file | |
cat $split >> tmp_file | |
mv -f tmp_file $FILENAME-$split.csv | |
rm $split | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment