consolidate all repos to one for archive
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
# dodajanje stikov
|
||||
./imenik_26097.sh -dodaj -ime "Nikola" -priimek "Petrov" -naslov "Ulica cesta" -posta 2000 -kraj "Maribor" -tel 123456789
|
||||
./imenik_26097.sh -dodaj -ime "Zan" -priimek "Pols" -naslov "Lika" -posta 2000 -kraj "Maribor" -tel 123456789
|
||||
./imenik_26097.sh -dodaj -ime "Nejc" -priimek "Kranjc" -naslov "Gosposvedska cesta" -posta 2000 -kraj "Maribor" -tel 123456789
|
||||
./imenik_26097.sh -dodaj -ime "Jan" -priimek "Polo" -naslov "HHAA" -posta 459 -kraj "Ljubljana" -tel 123456789
|
||||
./imenik_26097.sh -dodaj -ime "Jan" -priimek "Polo"
|
||||
|
||||
# iskanje stikov
|
||||
./imenik_26097.sh -isci -ime "Jan"
|
||||
./imenik_26097.sh -isci -posta 459
|
||||
./imenik_26097.sh -isci -ime "Nikola" -priimek "Petrov"
|
||||
|
||||
# ker so id nakjucni ga na tak nacin pridobi, zbran je tretji v tem primeru
|
||||
id=$(awk -F";" 'NR==3{print $1}' "imenik_26097.dat")
|
||||
|
||||
# spreminjanje stikov
|
||||
./imenik_26097.sh -uredi -id "$id" -ime "IME"
|
||||
./imenik_26097.sh -uredi -id "$id" -priimek "PRIIMEK"
|
||||
|
||||
# brisanje stikov
|
||||
./imenik_26097.sh -izbrisi -id "$id"
|
119
semester_4/sistemska_administracija/Naloga_1/imenik_26097.sh
Normal file
119
semester_4/sistemska_administracija/Naloga_1/imenik_26097.sh
Normal file
@@ -0,0 +1,119 @@
|
||||
#!/bin/bash
|
||||
|
||||
input=("" "" "" "" "" "" "")
|
||||
|
||||
myFile=imenik_26097.dat
|
||||
|
||||
function potrdi(){
|
||||
read -p "Potrdi? y/n : " -n 1 -r
|
||||
if [[ $REPLY != "y" ]]; then
|
||||
echo ""
|
||||
echo "Prekinjeno!"
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
}
|
||||
|
||||
function isciPod(){
|
||||
formString=$(printf '%s;' "${input[@]/#/.*}")
|
||||
|
||||
if grep -q "$formString" "$myFile"; then
|
||||
grep "$formString" "$myFile"
|
||||
else
|
||||
echo "Ni kontakta"
|
||||
fi
|
||||
}
|
||||
|
||||
function urediPod(){
|
||||
|
||||
# The '-F' option specifies the field separator as a semicolon and the '-v' option creates a variable 'ref' with the value of the first element of the 'input' array.
|
||||
# The pattern to search for is '$1==ref', which means the first field of the line (i.e., the part of the line before the first semicolon) should match the value of 'ref'.
|
||||
searchedLine=$(awk -F';' -v ref="${input[0]}" '$1==ref {print}' $myFile)
|
||||
if [[ $searchedLine == "" ]]; then
|
||||
echo "ERROR: Ni osebe z tem id"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
IFS=';' read -r -a array <<< "$searchedLine"
|
||||
for i in "${!input[@]}"; do
|
||||
[[ "${input[$i]}" != "" ]] && array[$i]="${input[$i]}"
|
||||
done
|
||||
newLine=$(IFS=';' ; echo "${array[*]}")
|
||||
|
||||
# s substitution
|
||||
# g all occurrences of the searched string should be replaced
|
||||
sed -i "s|${searchedLine}|${newLine}|g" $myFile
|
||||
echo "Urejeno uspesno."
|
||||
}
|
||||
|
||||
function odstraniPod(){
|
||||
#-i modify the file in-place.
|
||||
# /d delete
|
||||
sed -i "/${input[0]};/d" "$myFile"
|
||||
echo "Kontakt zbrisan."
|
||||
}
|
||||
|
||||
function dodajPod(){
|
||||
|
||||
input[0]=$(($RANDOM % 99999 + 1))
|
||||
|
||||
# Set any empty input values to "PRAZNO"
|
||||
for i in "${!input[@]}"
|
||||
do
|
||||
if [[ -z "${input[$i]}" ]]; then
|
||||
input[$i]="PRAZNO"
|
||||
fi
|
||||
done
|
||||
|
||||
# Append each input value to the file separated by ';'
|
||||
printf "%s;" "${input[@]}" >> $myFile
|
||||
echo "" >> $myFile
|
||||
|
||||
# Print success message
|
||||
echo "Kontakt dodan ${input[@]}"
|
||||
}
|
||||
|
||||
# The `! -f` operator checks if the file does not exist.
|
||||
if [ ! -f "$myFile" ]; then
|
||||
echo "" > $myFile
|
||||
fi
|
||||
|
||||
selection=$1
|
||||
|
||||
shift
|
||||
while [ $# -gt 0 ] ; do
|
||||
case $1 in
|
||||
-id) input[0]="$2" ;;
|
||||
-ime) input[1]="$2" ;;
|
||||
-priimek) input[2]="$2" ;;
|
||||
-naslov) input[3]="$2" ;;
|
||||
-posta) input[4]="$2" ;;
|
||||
-kraj) input[5]="$2" ;;
|
||||
-tel) input[6]="$2" ;;
|
||||
*)
|
||||
echo "ERROR napacen kljuc $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
shift
|
||||
done
|
||||
|
||||
potrdi
|
||||
|
||||
# izbiranje funkcije
|
||||
case $selection in
|
||||
-dodaj)
|
||||
dodajPod
|
||||
"$@" ;;
|
||||
-izbrisi)
|
||||
odstraniPod "$@" ;;
|
||||
-isci)
|
||||
isciPod "$@" ;;
|
||||
-uredi)
|
||||
urediPod "$@" ;;
|
||||
*)
|
||||
echo "ERROR napacen ukaz $selection"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
Reference in New Issue
Block a user