-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshow_table.sh
More file actions
47 lines (37 loc) · 1011 Bytes
/
show_table.sh
File metadata and controls
47 lines (37 loc) · 1011 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
39
40
41
42
43
44
45
46
#!/usr/bin/bash
# $1 is the name of the database you are currently using
clear
echo
list_tables $1
echo
echo -e "${GREEN}Showing a table in $1 database${NC}"
echo
while [[ true ]]; do
echo -ne "${PROMPT}Enter The Name Of The Table : ${NC}"
#back
if ! read table_name; then
return
fi
#check for empty string
if ! is_not_null $table_name; then
echo
echo -e "${RED}Name Cannot Be Null!${NC}"
continue
fi
#check for existing table name
if ! find_table $1 $table_name; then
echo
echo -e "${RED}Table Does not Exist!${NC}"
continue
fi
break
done
# printing the table columns from the metadata
awk -v var=$table_name 'BEGIN {FS=":"; print "\t\tTable Name: " var "\n"} {if(NR>1) printf $1"<"$2">\t\t"} END{printf "\n"}' "./Databases/$1/${table_name}_template"
# printing the table cells from the file itself
awk 'BEGIN{FS=":";OFS="\t\t\t";ORS="\n";}{ $1=$1; print substr($0, 1, length($0)-1) }' "./Databases/$1/$table_name"
echo
echo
echo "press Enter to return!"
read
return