Last active
February 15, 2021 12:54
-
-
Save rcapile/f7e57cd2ff229ec3f1c973170cefd941 to your computer and use it in GitHub Desktop.
scripts
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 | |
set -u | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: split-csv.sh file chunks" | |
exit 1 | |
fi | |
FILE=$1 | |
CHUNKS=$2 | |
if [ ! -f "$FILE" ]; then | |
echo "File $FILE not found" | |
exit 1; | |
fi | |
if [ -f temp-tailed ]; then | |
rm temp-tailed | |
fi | |
tail -n +2 "$FILE" > temp-tailed | |
split temp-tailed -n $CHUNKS -d ${FILE}_ | |
for chunk in ${FILE}_* | |
do | |
head -n 1 "$FILE" > tmp_file | |
cat $chunk >> tmp_file | |
mv -f tmp_file ${chunk}.csv | |
done | |
rm temp-tailed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment