-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip_sql
More file actions
executable file
·110 lines (94 loc) · 1.75 KB
/
Copy pathzip_sql
File metadata and controls
executable file
·110 lines (94 loc) · 1.75 KB
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
#!/bin/bash
# simple script to covert the US.txt file into SQL
# formatted text. Uses CAT to output results
# temp files
datafile=./tempfile$$
TEMP=./tempLoop$$
tempCol=./tempCol$$
OUT=./tempOut$$
tempMed=./tempMed$$
# function to force remove temp files
function removeAll {
rm -f $datafile
rm -f $TEMP
rm -f $tempCol
rm -f $OUT
rm -f $tempMed
exit
}
# trap rm temp files
trap "removeAll; exit 1" INT HUP TERM
# stdinput cat in user input into temp file
if [ "$#" = "1" ]
then
# check file not empty
cat $1 > $datafile
wordCount=$(wc -w < $datafile)
if ((wordCount != 0))
then
# main loop for copy to SQL
while read myLine
do
echo -n "(" >> $OUT
echo "$myLine" > $TEMP
count=$(wc -w < $TEMP)
if (($count != 0))
then
for ((i=1; i<=11; i++))
do
if ((i == 2))
then
STR=$(cut -d" " -f$i $TEMP)
echo -n "'">> $OUT
echo -n $STR >> $OUT
echo -n "', " >> $OUT
fi
if ((i == 3))
then
STR=$(cut -d" " -f$i $TEMP)
echo -n "'">> $OUT
echo -n $STR >> $OUT
echo -n "'," >> $OUT
fi
if ((i == 5))
then
STR=$(cut -d" " -f$i $TEMP)
echo -n "'">> $OUT
echo -n $STR >> $OUT
echo -n "'," >> $OUT
fi
if ((i == 10))
then
STR=$(cut -d" " -f$i $TEMP)
echo -n $STR >> $OUT
echo -n "," >> $OUT
fi
if ((i == 11))
then
STR=$(cut -d" " -f$i $TEMP)
echo -n $STR >> $OUT
fi
done
echo " )," >> $OUT
fi
done < $1
#remove temp files
rm $datafile
rm $TEMP
rm $tempCol
rm $tempMed
else
# if file is empty
echo "FILE IS EMPTY"
rm $datafile
exit 1
fi
else
# bad usage, echo usage and exit 1
echo "Usage: zip_sql {-rows|-cols} [file]" 1>&2
rm $datafile
exit 1
fi
cat $OUT
rm $OUT
exit 0