#!/bin/bash ###################################################################### # == tell v1.2 == # # Formatea Nmeros de Teléfono Españoles # # (C) Sebas 2002-2006 # # sebb@sebb.info # ###################################################################### ######################################################################## # tell permite dar un formato canónico a números de teléfono españoles # tell is a script that gives canonical format to spanish phone numbers ######################################################################## # Copyright (C) Sébastien Braud 2002-2006 sebb@sebb.info # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # sebb@sebb.info ######################################################################## # -I- INICIO # # Encabezados, GPL, ayuda. #################################################### if [ "$#" = 0 ]||[ "$#" != 2 ]&&[ "$1" != "-c" ]&&[ "$1" != "-p" ] > /dev/null ; then echo " ###################################################################### # == tell v1.2 == # # Formatea Teléfonos Españoles # # (C) Sebas 2002-2006 # # sebb@sebb.info # ###################################################################### => tell es un script destinado a formatear nmeros de teléfonos españoles. => tell necesita dos argumentos. => Uso: tell archivo_para_limpiar archivo_limpio. Ejemplo: lux@nix:~ tell feos.txt limpios.txt => tell coge como entrada un archivo de texto con los nmeros sin formato y separados por saltos de línea. => tell da como salida un archivo de texto con los nmeros formateados y separados por saltos de línea. => tell reconoce cualquier nmero de 9 dígitos que empiece por 9 o por 6, pero no trata líneas que contengan más de un número o que contengan el símbolo \"/\". => Esta versión de tell se escribió para GNU bash, version 2.05b para FreeBSD. Ha sido adaptada por lo cual debería funcionar en cualquier otra versión de Bash y de Linux. => Teclee tell -c para ver el copyright. => Teclee tell -p para ver una tabla de prefijos telefónicos españoles. => Teclee tell a secas para ver esta ayuda." # Copyright ####################################################################### elif [ "$1" = "-c" ] > /dev/null ; then echo " tell v1.2, Copyright (C) 2002-2006 Sebas - sebb@sebb.info tell v1.2 comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See GNU General Public License. http://www.gnu.org YOU ARE USING THIS PROGRAM AT YOUR OWN RISK. " # Tabla de prefijos de provincias ################################################# elif [ "$1" = "-p" ] > /dev/null ; then echo " PREFIJOS TELEFÓNICOS ESPAÑOLES Álava 945 La Coruña 981 Albacete 967 Las Palmas 928 Alicante 96 Leon 987 Almería 950 Lérida 973 Asturias 98 Lugo 982 Ávila 920 Madrid 91 Badajoz 924 Málaga 95 Barcelona 93 Melilla 95 Burgos 947 Murcia 968 Cáceres 927 Navarra 948 Cádiz 956 Orense 988 Cantabria 942 Palencia 979 Castellón 964 Pontevedra 986 Ceuta 956 Salamanca 923 Ciudad Real 926 Santa Cruz Tenerife 922 Córdoba 957 Segovia 921 Cuenca 969 Sevilla 95 Gerona 972 Soria 975 Gipúzcoa 943 Tarragona 977 Granada 958 Teruel 978 Guadalajara 949 Toledo 925 Huelva 959 Valencia 96 Huesca 974 Valladolid 983 Islas Baleares 971 Vizkaia 94 Jaén 953 Zamora 980 Zaragoza 976" elif [ "$#" = 2 ] ; then echo " tell v1.2, Copyright (C) 2002-2006 Sebas - sebb@sebb.info tell v1.2 comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See GNU General Public License. http://www.gnu.org YOU ARE USING THIS PROGRAM AT YOUR OWN RISK. " # -II- FORMATEO # lista_entrada=$1 lista_salida=$2 # Declaro la función principal function ordena_tells() { # Declaro función que encuentra y trata los 91, 93 function dedos() { [ "${numero:0:2}" == "91" ]||[ "${numero:0:2}" == "93" ]&&[ "${#numero}" = "9" ]&&echo "${numero:0:2} ${numero:2:3} ${numero:5:2} ${numero:7:2}" >> $lista_salida } # Declaro función que encuentra y trata los 958, 900, 608 function detres() { [ "${numero:0:3}" == "920" ]||[ "${numero:0:3}" == "921" ]||[ "${numero:0:3}" == "922" ]||[ "${numero:0:3}" == "923" ]||[ "${numero:0:3}" == "924" ]||[ "${numero:0:3}" == "925" ]||[ "${numero:0:3}" == "926" ]||[ "${numero:0:3}" == "927" ]||[ "${numero:0:3}" == "928" ]||[ "${numero:0:3}" == "971" ]||[ "${numero:0:3}" == "972" ]||[ "${numero:0:3}" == "973" ]||[ "${numero:0:3}" == "974" ]||[ "${numero:0:3}" == "975" ]||[ "${numero:0:3}" == "976" ]||[ "${numero:0:3}" == "977" ]||[ "${numero:0:3}" == "978" ]||[ "${numero:0:3}" == "979" ]||[ "${numero:0:3}" == "942" ]||[ "${numero:0:3}" == "943" ]||[ "${numero:0:3}" == "945" ]||[ "${numero:0:3}" == "947" ]||[ "${numero:0:3}" == "948" ]||[ "${numero:0:3}" == "949" ]||[ "${numero:0:3}" == "950" ]||[ "${numero:0:3}" == "953" ]||[ "${numero:0:3}" == "955" ]||[ "${numero:0:3}" == "956" ]||[ "${numero:0:3}" == "957" ]||[ "${numero:0:3}" == "958" ]||[ "${numero:0:3}" == "959" ]||[ "${numero:0:3}" == "964" ]||[ "${numero:0:3}" == "967" ]||[ "${numero:0:3}" == "968" ]||[ "${numero:0:3}" == "969" ]||[ "${numero:0:3}" == "980" ]||[ "${numero:0:3}" == "981" ]||[ "${numero:0:3}" == "982" ]||[ "${numero:0:3}" == "983" ]||[ "${numero:0:3}" == "986" ]||[ "${numero:0:3}" == "987" ]||[ "${numero:0:3}" == "988" ]||[ "${numero:0:2}" == "90" ]||[ "${numero:0:1}" == "6" ]&&[ "${#numero}" = "9" ]&&echo "${numero:0:3} ${numero:3:2} ${numero:5:2} ${numero:7:2}" >> $lista_salida } # Declaro función que encuentra y trata los raros tipo 95 212 12 12 # Ha de ser ejecutada "obligatoriamente después" de la función "detres" function raros() { [ "${numero:0:2}" == "94" ]||[ "${numero:0:2}" == "95" ]||[ "${numero:0:2}" == "96" ]||[ "${numero:0:2}" == "98" ]&&[ "${#numero}" = "9" ]&&echo "${numero:0:2} ${numero:2:3} ${numero:5:2} ${numero:7:2}" >> $lista_salida } # Declaro función que trata los malos function malos() { echo $numero >> $lista_salida } # Ejecuto el formateo, en el orden preciso dedos||detres||raros||malos } # Fin de la función principal # -III- EJECUCIÓN # IFS=" "; # OJO con el sed: la ltima expresión es un tab. # Si el editor lo cambia a espacios, feo. for numero in `cat $lista_entrada` do if [ "`echo $numero | grep "/" > /dev/null ; echo $?`" = "0" ] ; then echo $numero >> $lista_salida else numero=`echo $numero | sed -e 's/ //g' -e 's/\.//g' -e 's/://g' -e 's/,//g' -e 's/;//g' -e 's/\\\//g' -e 's/-//g' -e 's/_//g' -e 's/&//g' -e 's///g' -e 's/\[//g' -e 's/\]//g' -e 's/;//g' -e 's/[[:alpha:]]//g' -e 's/#//g' -e 's/ //g'` ordena_tells fi done