forked from mo7amedsalah/DBEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_record.sh
executable file
·68 lines (49 loc) · 1.22 KB
/
delete_record.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
#!/bin/bash
clear
source "functions"
source $(pwd)/use_Database.sh
function get_data_row
{
#ids=$(awk -F":" 'NR>3 {print '$'$pk}' "$filename" | cut -f $pk )
ids=$(awk -F":" 'NR>3 {print '$'$pk}' "$filename" | cut -d":" -f $pk | tr '\n' ' ')
read -r -a myids <<< "$ids"
length="${#myids[@]}"
flage=0
for ((i=0;i<length;i++))
do
if [[ ${myids[$i]} == $1 ]]
then
flage=1
break
else
flage=0
fi
done
if [[ "$flage" -eq 1 ]]
then
#grep "^${myids[$i]}" "$filename"
grep -v "^${myids[$i]}" "$filename" > temp && mv temp "$filename"
echo "your ${myids[$i]} deleted successfully "
else
echo "not found"
fi
}
echo "enter your file:"
read filename
if [[ -f "$filename" ]]
then
echo "your file found"
echo "enter the id :"
read readline
if [[ "$readline" =~ ^[1-9]+$ ]]
then
get_structure_of_table
get_data_row "$readline"
else
echo "invalid value"
fi
else
echo "your file does not exist"
fi
cd ..
source "DatabaseEngine.sh";