-
Notifications
You must be signed in to change notification settings - Fork 0
/
squt
executable file
·49 lines (40 loc) · 884 Bytes
/
squt
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
#!/bin/bash
#Autogenerated script template
# Variable declarations
#========================================
me=${0##*/}
fields=""
delimiter=' '
usage (){
echo "$me - Squeeze repeated chars and cut fields from stdin"
echo "Usage: $me fields [-d delimChar=' ']"
echo -e "\nExample: echo '1 skip 3' | squt 1,3"
exit 1
}
# Parse options
#=======================================
while getopts "hd:" opt; do
case $opt in
h )
usage
;;
d )
delimiter=$OPTARG
;;
\? )
usage
;;
: )
echo "Option requires an argument: $OPTARG"
exit
;;
esac
done
shift $((OPTIND -1))
if [ "$#" -lt 1 ]; then
usage
fi
fields=$1
while read line; do
echo $line | tr -s "$delimiter" | cut -d "$delimiter" -f "$fields"
done