Last active
April 3, 2024 06:48
-
-
Save ipoddubny/d736dcc185b3d44ef33b to your computer and use it in GitHub Desktop.
Импорт базы abc, def-кодов и операторов с сайта Россвязи и поиск номеров в ней. Обновлено 13.07.2019
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 | |
function getCSV { | |
echo "Downloading $1..." | |
curl -s https://rossvyaz.ru/data/$1.csv |\ | |
iconv -f cp1251 -t utf8 |\ | |
sed -e 's/[[:space:]]*;[[:space:]]*/;/g' -e '/^$/d' |\ | |
awk '{ split($0,a,";"); print a[1] ";" a[2] ";" a[3] ";" a[4] ";" a[5] ";" a[6] ", " a[7] ", " a[8] ", " a[9] ", " a[10] }' |\ | |
sed -e 's/\(,[[:space:]]\)*$//' > $2.csv | |
} | |
getCSV DEF-9xx def | |
getCSV ABC-3xx abc3 | |
getCSV ABC-4xx abc4 | |
getCSV ABC-8xx abc8 | |
echo "Creating database..." | |
/bin/rm -f db.sqlite3 | |
sqlite3 db.sqlite3 <<SQL | |
CREATE TABLE abcdef ( | |
code varchar(3), | |
dstart varchar(7), | |
dend varchar(7), | |
capacity int, | |
operator varchar, | |
region varchar | |
); | |
.mode csv | |
.separator ';' | |
.import def.csv abcdef | |
.import abc3.csv abcdef | |
.import abc4.csv abcdef | |
.import abc8.csv abcdef | |
CREATE INDEX 'abcdef_code_start_end' ON abcdef ('code', 'dstart', 'dend'); | |
SQL |
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 | |
if [[ $# -ne 1 || ${#1} -ne 10 ]]; then | |
echo "Usage: $0 9991112233" | |
exit | |
fi | |
code=${1:0:3} | |
num=${1:3:7} | |
sqlite3 db <<SQL | |
.mode line | |
SELECT * FROM abcdef WHERE code = '${code}' AND '${num}' BETWEEN dstart AND dend; | |
SQL |
Приветствую,
подскажите пожалуйста как сделать выборку со своего списка номеров локальна на компе (ос линукс) с полученной из getdata.sh db.sqlite3запускаю :
$sh lookup.sh
или sh $lookup.sh 9991112233
mas@pk ~/Д/testDEF9 [2]> sh lookup.sh 9991112233 lookup.sh: 3: [[: not found lookup.sh: 3: 0: not found lookup.sh: 8: Bad substitution mas@pk ~/Д/testDEF9 [2]> sh lookup.sh lookup.sh: 3: [[: not found lookup.sh: 3: 0: not found lookup.sh: 8: Bad substitution mas@pk ~/Д/testDEF9 [2]>
Не нужно запускать из под sh, просто сделайте chmod +x lookup.sh, а затем запустите ./lookup.sh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Приветствую,
подскажите пожалуйста как сделать выборку со своего списка номеров локальна на компе (ос линукс) с полученной из getdata.sh db.sqlite3
запускаю :
$sh lookup.sh
или sh $lookup.sh 9991112233
mas@pk ~/Д/testDEF9 [2]> sh lookup.sh 9991112233 lookup.sh: 3: [[: not found lookup.sh: 3: 0: not found lookup.sh: 8: Bad substitution mas@pk ~/Д/testDEF9 [2]> sh lookup.sh lookup.sh: 3: [[: not found lookup.sh: 3: 0: not found lookup.sh: 8: Bad substitution mas@pk ~/Д/testDEF9 [2]>