-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert-into-table.sh
43 lines (28 loc) · 1.06 KB
/
insert-into-table.sh
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
#!/bin/bash
echo "---------------------insert into table---------------------------"
read -p "enter table you want to insert into : " tb_name
data=.$table_name@metadata
if [[ -f $db_name/$tb_name ]]; then
colsNum=$(awk 'BEGIN{FS=":"}{if(NR == 1) print NF}' $db_name/$metadata)
if [[ -s $db_name/$tb_name ]]; then
ID=$(tail -1 $db_name/$tb_name | cut -d':' -f1)
auto_incremnt=$(($ID + 1))
echo -n "$auto_incremnt:" >>$db_name/$tb_name
else
echo -n "1:" >>$db_name/$tb_name
fi
for i in $(seq 2 $colsNum); do
fieldName=$(awk 'BEGIN{FS=":"}{if(NR == 1) print $'$i'}' $dbname/$metadata)
colType=$(awk 'BEGIN{FS=":"}{if(NR == 2) print $'$i'}' $dbname/$metadata)
read -p "Enter $fieldName To Insert Into It : " column_value
if [ $i -eq $colsNum ]; then
echo -n "$column_value" >>$db_name/$tb_name
else
echo -n "$column_value:" >>$db_name/$tb_name
fi
done
echo >>$db_name/$tb_name
else
echo "File Doesn't exist"
fi
./ connect_table.sh