2013-08-27 15:14:44 +04:00
|
|
|
#!/bin/bash
|
|
|
|
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
|
|
|
|
2014-01-21 12:07:28 +04:00
|
|
|
ALIASES=(awkrun awkfsv2csv awkcsv mergecsv sortcsv)
|
2013-08-27 15:14:44 +04:00
|
|
|
if [ "$#" -eq 1 -a "$1" == --nutools-makelinks ]; then
|
|
|
|
# créer les liens
|
|
|
|
scriptname="$(basename "$0")"
|
2014-01-21 12:07:28 +04:00
|
|
|
for alias in "${ALIASES[@]}"; do
|
2013-08-27 15:14:44 +04:00
|
|
|
ln -s "$scriptname" "$alias"
|
2014-01-21 12:07:28 +04:00
|
|
|
ln -s "$scriptname" "l$alias"
|
2013-08-27 15:14:44 +04:00
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
source "$(dirname "$0")/ulib/ulib" &&
|
|
|
|
urequire DEFAULTS awk ||
|
|
|
|
exit 1
|
|
|
|
|
2014-01-21 12:07:28 +04:00
|
|
|
# si on lance le script uawk, donner la possibilité de choisir l'outil
|
|
|
|
if [ "$scriptname" == uawk ] && array_contains ALIASES "${1#l}"; then
|
|
|
|
scriptname="$1"
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
# choix de la version des scripts: tient compte de la locale ou non
|
|
|
|
if [ "${scriptname#l}" != "$scriptname" ]; then
|
|
|
|
prefix=l
|
|
|
|
Clang=
|
|
|
|
else
|
|
|
|
prefix=c
|
|
|
|
Clang=1
|
|
|
|
fi
|
|
|
|
|
2013-08-27 15:14:44 +04:00
|
|
|
if [ "$scriptname" == "awkcsv" ]; then
|
|
|
|
[ $# -eq 1 -a "$1" == --help ] && exit_with uecho "$scriptname: wrapper autour de awk pour traiter des fichier csv
|
2014-01-21 12:07:28 +04:00
|
|
|
${Clang:+note: ce script ne tient pas compte de la locale: il travaille avec LANG=C
|
|
|
|
}
|
2013-08-27 15:14:44 +04:00
|
|
|
USAGE
|
2014-01-21 12:07:28 +04:00
|
|
|
$scriptname [-b before] -e script [-a after] -- [headers...] [-- inputfiles...]
|
2013-08-27 15:14:44 +04:00
|
|
|
|
|
|
|
$__AWKCSV_HELP"
|
|
|
|
|
2014-01-21 12:07:28 +04:00
|
|
|
"${prefix}awkcsv" "$@"
|
2013-08-27 15:14:44 +04:00
|
|
|
|
2014-01-21 11:35:07 +04:00
|
|
|
elif [ "$scriptname" == "awkfsv2csv" ]; then
|
|
|
|
[ $# -eq 1 -a "$1" == --help ] && exit_with uecho "$scriptname: wrapper autour de awk pour transformer un fichier à colonnes fixes en fichier csv
|
2014-01-21 12:07:28 +04:00
|
|
|
${Clang:+note: ce script ne tient pas compte de la locale: il travaille avec LANG=C
|
|
|
|
}
|
2014-01-21 11:35:07 +04:00
|
|
|
USAGE
|
2014-01-21 12:07:28 +04:00
|
|
|
$scriptname [options] -- [header:sizes...] [-- inputfiles...]
|
2014-01-21 11:35:07 +04:00
|
|
|
|
|
|
|
$__AWKFSV2CSV_HELP"
|
|
|
|
|
2014-01-21 12:07:28 +04:00
|
|
|
"${prefix}awkfsv2csv" "$@"
|
2014-01-21 11:35:07 +04:00
|
|
|
|
2013-08-27 15:14:44 +04:00
|
|
|
elif [ "$scriptname" == "mergecsv" ]; then
|
|
|
|
[ $# -eq 1 -a "$1" == --help ] && exit_with uecho "$scriptname: fusionner deux fichiers csv sur un champ commun
|
2014-01-21 12:07:28 +04:00
|
|
|
${Clang:+note: ce script ne tient pas compte de la locale: il travaille avec LANG=C
|
|
|
|
}
|
2013-08-27 15:14:44 +04:00
|
|
|
USAGE
|
|
|
|
$scriptname [options] left right -k field
|
|
|
|
|
|
|
|
$__MERGECSV_HELP"
|
|
|
|
|
2014-01-21 12:07:28 +04:00
|
|
|
"${prefix}mergecsv" "$@"
|
2013-08-27 15:14:44 +04:00
|
|
|
|
|
|
|
elif [ "$scriptname" == "sortcsv" ]; then
|
|
|
|
[ $# -eq 1 -a "$1" == --help ] && exit_with uecho "$scriptname: trier un fichier csv sur un champ
|
2014-01-21 12:07:28 +04:00
|
|
|
${Clang:+note: ce script ne tient pas compte de la locale: il travaille avec LANG=C
|
|
|
|
}
|
2013-08-27 15:14:44 +04:00
|
|
|
USAGE
|
|
|
|
$scriptname [options] input -k field
|
|
|
|
|
|
|
|
$__SORTCSV_HELP"
|
|
|
|
|
2014-01-21 12:07:28 +04:00
|
|
|
"${prefix}sortcsv" "$@"
|
2013-08-27 15:14:44 +04:00
|
|
|
|
|
|
|
else
|
|
|
|
[ $# -eq 1 -a "$1" == --help ] && exit_with uecho "$scriptname: wrapper autour de awk rajoutant des fonctions supplémentaires
|
2014-01-21 12:07:28 +04:00
|
|
|
${Clang:+note: ce script ne tient pas compte de la locale: il travaille avec LANG=C
|
|
|
|
}
|
2013-08-27 15:14:44 +04:00
|
|
|
USAGE
|
|
|
|
$scriptname [var=value...] script [-- inputfiles...]
|
|
|
|
|
|
|
|
Lancer awk avec un script préparé de la manière spécifiée ci dessous.
|
|
|
|
|
|
|
|
$__AWKDEF_HELP"
|
|
|
|
|
2014-01-21 12:07:28 +04:00
|
|
|
"${prefix}awkrun" -f "$@"
|
2013-08-27 15:14:44 +04:00
|
|
|
fi
|