Last active
January 8, 2021 05:36
-
-
Save metric-space/9e7ce85a1161095d07f2a7dd85ba2273 to your computer and use it in GitHub Desktop.
split csv into n files with each file containing content as well as csv header
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
inputfile=$1 | |
filename="${inputfile%.*}" | |
line_count=$(wc -l < $1) | |
row_count=$((${line_count} - 1)) | |
movement=$(($row_count/$2)) | |
i=0 | |
j=1 | |
while [ $j -lt $row_count ] | |
do | |
# echo $(($j + 1)) | |
# echo $(($j + $movement)) | |
t="${filename}-${i}.csv" | |
touch $t | |
head -n 1 $1 > $t | |
cat $1 | sed -n "$(($j + 1)),$(($j + $movement ))p" >> $t | |
j=$[$j + movement] | |
i=$[$i+1] | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment