-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelect.sh
95 lines (84 loc) · 2.28 KB
/
Select.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
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
#!/usr/bin/bash
#description: select all table or select specifc column or select sepecific row
#select all table -->okay
#check table is exist or no --->okay
#select column check is exist in table or no --->okay
#select this column if it is exist --->okay
function checkInt()
{
local re='^([0-9]+)*$'
(( ${#1} > 16 )) && return 1
[[ "$1" =~ $re ]]
}
testValidInt() {
if checkInt "$1"; then
return 0
else
return 1
fi
}
read -p "Please,Enter name table to select it: " selTable
if [ ! ${#selTable} -eq 0 ]
then
if [ -f ./$selTable ]
then
echo "Please,choose what do you want to select from menu? "
select sel in "Select all data From Table" "Select Column" "Select Row" "Exit"
do
Numcol=($(awk 'BEGIN{FS=":";} END{print NR}' ./$selTable.Mdata))
Numrows=($(awk 'BEGIN{FS=":";} END{print NR}' ./$selTable))
case $sel in
"Select all data From Table")
echo "Select this Table"
echo "-------------------------------------"
cat $selTable
echo "-------------------------------------"
;;
"Select Column")
read -p "Enter Column Number: " cnum
testValidInt "$cnum"
if [ $? -eq 0 ]
then
if [ $cnum -le $Numcol ]
then
echo "-------------------------------------"
cat $selTable | cut -d: -f$cnum # -f field
echo "-------------------------------------"
else
echo "Doesn't Exist $cnum Numbers Columns"
fi
else
echo "Sorry,You Must enter number column only"
fi
;;
"Select Row")
read -p "Enter Row Number: " nrow
testValidInt "$nrow"
if [ $? -eq 0 ]
then
if [ $nrow -le $Numrows ]
then
echo "-------------------------------------"
sed -n "$nrow p" ./$selTable # -n for number of row
echo "-------------------------------------"
else
echo "Doesn't Exist $nrow Numbers Rows"
fi
else
echo "echo "Sorry,You Must enter number row only""
fi
;;
"Exit")
break
;;
*)
echo "You must choose correct number in this menu"
;;
esac
done
else
echo "Doesn't Exist this table"
fi
else
echo "You must enter input,Can't input Empty"
fi