Last active
October 7, 2016 09:04
-
-
Save Rittyan/009cd305c3d39d96f29a4e9e2cc4e6bc to your computer and use it in GitHub Desktop.
half split csv
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/sh | |
# CSVファイルを二分割する | |
header=`head -n 1 $1` | |
filename=`basename $1` | |
dirname=`dirname $1` | |
echo split_${filename} | |
# | sed -e "s/^$header" | |
CNT=0 | |
fileNum=1 | |
lineCount=0 | |
# 行数をカウントして分割する行数を決定 | |
while read line; | |
do | |
lineCount=$((lineCount+1)) | |
printf "\r linecount: ${lineCount}:\r" | |
done < $1 | |
splitLines=$[($lineCount-1)/2] | |
echo "finish count file lines lines:{$lineCount}" | |
cd ${dirname} | |
# もっかい読み込んでファイルを分割 | |
while read line; | |
do | |
echo ${line} >> ${filename%.*}_${fileNum}.${filename##*.} | |
CNT=$((CNT+1)) | |
if [ $CNT = $splitLines ] ; then | |
fileNum=$((fileNum+1)) | |
echo ${header} > ${filename%.*}_${fileNum}.${filename##*.} | |
fi | |
printf "\r fileNum:${fileNum} inputCount : ${CNT}\r" | |
done < $1 | |
echo "Finished Split CSV!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment