Created
October 22, 2015 12:16
-
-
Save dynax60/96bb9457fb668255c7e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| PATH=/bin:/usr/bin | |
| file=Kody_DEF-9kh.csv | |
| die() { | |
| echo "Cannot download $file" >&2 | |
| exit 1 | |
| } | |
| test -s $file && mv $file ${file}.previous \ | |
| && wget http://www.rossvyaz.ru/docs/articles/Kody_DEF-9kh.csv | |
| ! test -s $file && die | |
| mysql -s -u root def << "EOF" | |
| DROP TABLE IF EXISTS `def`; | |
| /*!40101 SET @saved_cs_client = @@character_set_client */; | |
| /*!40101 SET character_set_client = utf8 */; | |
| CREATE TABLE `def` ( | |
| `def_from` bigint(15), | |
| `def_to` bigint(15), | |
| `def_operator` varchar(150) DEFAULT NULL, | |
| PRIMARY KEY (`def_from`,`def_to`) | |
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |
| EOF | |
| iconv -f windows-1251 -t utf-8 $file | perl -lne '@a=grep { s/^[\s\t]+//; s/[\s\t]+$//; } split /;/; print "$a[0]$a[1];$a[0]$a[2];$a[4]"' > tmp | |
| perl -pi -e 's{^;\n}{}g' tmp | |
| mysql -s --user=root -e "set foreign_key_checks=0; set sql_log_bin=0; set unique_checks=0; load data local infile 'tmp' into table def fields terminated by ';' lines terminated by '\n' ignore 1 lines (def_from, def_to, def_operator);" def | |
| rm -f tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment