-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathcsvheader
More file actions
executable file
·38 lines (34 loc) · 799 Bytes
/
csvheader
File metadata and controls
executable file
·38 lines (34 loc) · 799 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='
' # newline
while getopts "d:tq:r:" arg; do
case $arg in
d)
DEL=${OPTARG}
;;
t)
DEL=' ' # tab
;;
q)
QUO=${OPTARG}
;;
r)
REC=${OPTARG}
;;
*)
echo $USAGE;
exit 1;
;;
esac
done
CSVQUOTE=`which csvquote` || CSVQUOTE="./csvquote"
if [ ! -f $CSVQUOTE ]; then
echo "csvquote program not found. exiting"
exit 1
fi
$CSVQUOTE $@ | head -n 1 | tr "$DEL" '\n' | nl -ba | $CSVQUOTE -u -d "$DEL" -q "$QUO" -r "$REC"