1 2 3 4 5 6 7 8 9 10 11 |
# step.1 convert character set iconv -f SHIFT-JIS -t UTF-8 KEN_ALL.CSV > KEN_ALL_UTF8.CSV # step.2 remove columns not to use cut -d ',' -f 3-9 KEN_ALL_UTF8.CSV > KEN_ALL_UTF8_MIN.CSV # step.3 convert txt to insert sql awk '{if ( NR % 5000 == 1 ) result="INSERT INTO zipcode VALUES ("$0"),"; else if ( NR % 5000 == 0 ) result="("$0");"; else result="("$0"),"; print result;}' KEN_ALL_UTF8_MIN.CSV | sed '$ s/.$/;/' > KEN_ALL_UTF8_MIN.SQL # step.4 prepend truncate sql { echo "TRUNCATE TABLE zipcode;"; cat KEN_ALL_UTF8_MIN.SQL; } > KEN_ALL_UTF8_MIN_WITH_TRUNCATE.SQL |