/usr/bin/gbconvtable is in gbutils 5.7.0-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | #!/bin/sh
# gbconvtable ver. 5.6 Copyright (C) 2010-2015 Giulio Bottazzi
#default settings
pos=1
force="no"
dictfile=""
#read command line options; the position of the last option is saved
#in OPTIND
while getopts "d:c:f:h-:" opt
do
case $opt in
-)
case "${OPTARG}" in
help) help=yes;;
version) version=yes;;
esac;;
d) dictfile=$OPTARG;;
c) pos=$OPTARG;;
f) force=yes ; fstring=$OPTARG ;;
h) help=yes;;
\?) help=yes;;
esac
done
if [ "$version" = "yes" ]; then
cat - <<EOF
gbconvtable ver. 5.6
Copyright (C) 2010-2015 Giulio Bottazzi
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
(version 2) as published by the Free Software Foundation.
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.
Written by Giulio Bottazzi
Report bugs to <gbutils@googlegroups.com>
Package home page <http://cafim.sssup.it/~giulio/software/gbutils/index.html>
EOF
exit
fi
if [ "$help" = "yes" ]; then
cat - <<EOF
Replace keys with values at a given position of the input file. The
name of the dictionary file is provided on the command line with the
option 'dictfile'. It is a simple text file organized in two
columns. The first column contains the keys and the second column the
respective values. Obviously the values can be equal, but the keys
should be all different. Data are read from standard input and all
fields at position 'pos' are considered keys of the provided
dictionary and replaced with the associated keys. If 'pos' is not
specified it is assumed equal to 1. If 'pos' is larger than the number
of fields, no replacement takes place. If the option 'force' is not
set, only those fields which appears as keys in the dictionary file
are replaced.
Usage: gbconvtable [options]
Options:
-d name of the dictionary file
-c position of the column of keys to be replaced
-f forced look-up: substitute provided string for non defined keys
Examples:
gbconvtable -d dict_file -c 3 -f 'none' < input_file
This program requires awk or gawk.
EOF
exit
fi
if ! [ -e "$dictfile" ]; then
echo "provide a dictionary file with option -d. try $0 -h for help"
exit
fi
awk -v dictfile=$dictfile -v pos=$pos -v force=$force -v fstring=$fstring '
BEGIN {
#open dictionary file and build the dictionary
while ((getline line < dictfile ) > 0){
split(line,pair)
dict[pair[1]]=pair[2]
}
}
{
#replace the field and print it
if(NF>=pos){
if($pos in dict)
$pos=dict[$pos]
else{
if(force=="yes")
$pos=fstring
}
}
print $0
}
'
|