-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdropfromtable.sh
executable file
·52 lines (48 loc) · 945 Bytes
/
dropfromtable.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
#!/usr/bin/bash
select_column(){
echo 'enter your column number :'
read -r number_
if [[ ! $number_ =~ ^[0-9]+$ ]] ;
then
echo "error"
else
sed -i "$number_ d" $tname
fi
}
select_column2(){
echo 'enter your start number :'
read -r num_start
echo 'enter your end number :'
read -r num_end
if [[ ! $num_start =~ ^[0-9]+$ ]] ;
then
echo "error"
elif [[ ! $num_end =~ ^[0-9]+$ ]] ;
then
echo "error"
else
sed -i "$num_start,$num_end d" $tname
fi
}
echo "enter your table name "
read -r tname
if ! [ -e $tname -a -e $tname.rows ] ;
then
echo 'table dont exist '
else
echo "
enter your option
1) delete all
2) delete by column number
3) delete from line to line
0) Exit
:"
read -r option
case $option in
1) sed -i '1,$d' $tname ;;
2) select_column ;;
3) select_column2 ;;
0) exit ;;
*) echo 'error' ;;
esac
fi