forked from dbro/csvquote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsvheader
More file actions
executable file
·38 lines (34 loc) · 832 Bytes
/
Copy pathcsvheader
File metadata and controls
executable file
·38 lines (34 loc) · 832 Bytes
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
#!/bin/sh
# prints the first row of csv data with index numbers
USAGE="$0 [-d field_delimiter] [-t] [-q quote_character] [-r record_separator] [filename]"
# same defaults as csvquote
DEL=','
QUO='"'
REC='\n'
while getopts "d:tq:r:" arg; do
case $arg in
d)
DEL=${OPTARG}
;;
t)
DEL='\t'
;;
q)
QUO=${OPTARG}
;;
r)
REC=${OPTARG}
;;
*)
echo $USAGE;
exit 1;
;;
esac
done
shift `echo "$OPTIND - 1" | bc` # is there a better way to decrement?
CSVQUOTE=`which csvquote` || CSVQUOTE="./csvquote"
if [ ! -f $CSVQUOTE ]; then
echo "csvquote program not found. exiting"
exit 1
fi
$CSVQUOTE -d $DEL -q $QUO -r $REC $@ | head -n 1 | tr $DEL '\n' | nl -ba