Skip to content

Instantly share code, notes, and snippets.

@petrohs
Created August 20, 2020 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petrohs/32da08f7bf93bccb9c0988a6254fef1c to your computer and use it in GitHub Desktop.
Save petrohs/32da08f7bf93bccb9c0988a6254fef1c to your computer and use it in GitHub Desktop.
field_attr¦ Obtiene el correspondiente a field y attributes
#!/bin/sh
ayuda () { echo '
#===============================================================================
#
# SCRIPT: field_attr.sh
#
# USO: ./field_attr.sh [-f field] [-a attrib]
# ./field_attr.sh "field_id=17, attr_id=9"
#
# DESCRIPCION: Obtiene el correspondiente a field y attributes
# OPCIONES: -f Valor del field
# -a Valor del attribute
# DEPENDENCIAS: ---
# BUGS: ---
# NOTAS: ---
# URL: ---
# VERSIONES: 20160607 0.0.2 PetrOHS Parametros
# 20160607 0.0.1 PetrOHS Creacion
#===============================================================================
' | more;}
#ayuda
if [ "$1" = "-h" -o "$1" = "--help" -o "$1" = "--ayuda" -o "$1" = "" ]
then
ayuda;
exit 1;
fi
#leyendo opciones de linea comandos
while getopts a:f: _opciones
do
case "$_opciones" in
a)
AttriNum="$OPTARG";
if [ -n "${AttriNum}" -a $AttriNum = 0 ]; then exit 2; fi;
;;
f)
FieldNum="$OPTARG";
if [ -n "${FieldNum}" -a $FieldNum = 0 ]; then exit 2; fi;
;;
*)
ayuda;
exit 2;
;;
esac
done
shift `expr $OPTIND - 1`
#archivos
#FieldNum="79";
#AttriNum="9";
archivoFields=BSCS_Fields_apl.apl
archivoAttrib=BSCSAttributes_apl.apl
if [ ! -r "${archivoFields}" ]; then echo "no existe archivo Fields $archivoFields"; exit 3; fi;
if [ ! -r "${archivoAttrib}" ]; then echo "no existe archivo Attrib $archivoAttrib"; exit 3; fi;
#argumento
if [ -n "$1" ]
then
FieldNum=`echo "${1}" | cut -d"=" -f2 | cut -d"," -f1`;
AttriNum=`echo "${1}" | cut -d"=" -f3 | cut -d"," -f1`;
fi
#campos
if [ -n "$FieldNum" ]
then
cat "${archivoFields}" | tr -d ";" | awk -v aFieldNum=$FieldNum '{if($5 == aFieldNum){print "Field "aFieldNum": "substr($3,6);}}'
fi
if [ -n "$AttriNum" ]
then
cat "${archivoAttrib}" | tr -d ";" | awk -v aAttriNum=$AttriNum '{if($5 == aAttriNum){print "Attri "aAttriNum": "substr($3,6);}}'
fi
#
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment