-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect-from-table.sh
42 lines (30 loc) · 1.05 KB
/
select-from-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
#!/bin/bash
echo "-------------------select from table--------------------------"
read -p "enter table to select from : " table_name
select choice in "select all" "select using PK" "Exit"; do
case $choice in
"Select All")
output=$(cat "$db_name/$tb_name")
for line in $output; do
echo $line
done
echo "All Records Are Selected Successfully In $tb_name "
;;
"Select using PK")
read -p "Enter the primary key: " pk
ID_exist=$(awk -F ":" '{if($1=="'$pk'") print "Primary_key_exist" }' $db_name/$tb_name)
if [ "$ID_exist" = "Primary_key_exist" ]; then
Record_no=$(awk -F ":" '{if($1=="'$pk'") print $0}' $db_name/$tb_name)
echo $Record_no
echo " Record Is Selected Successfully from $tb_name "
else
echo "Primary key doesn't exist !! "
fi
;;
"Exit")
echo "Switched To Connect Database Menu"
. connect_table.sh
;;
*) echo "not in the choice" ;;
esac
done