Commit 2ca0db45 authored by Snehlata's avatar Snehlata

Dfirst

draft
D
rst
parent 0d7c2a82
We_did_our_best @ e6c500d8
Subproject commit e6c500d8b9279760bc62df1cc7766279b0b830ff
File added
File added
File added
#!/bin/bash
a="$1"
s=0
x=0
for ((i=1;i<=$((a));i++)); do
x=$((i*i))
s=$((s+x))
done
echo "$s"
File added
File added
File added
#!/bin/sh
path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd "$path"
cd "$1"
ls -l | grep -c ^d
File added
File added
File added
File added
File added
#! /bin/bash
#input from q3_in.txt after sorting output in q3_in.txt
grep "[5]" q3_in.txt | sort >q3_out.txt
This diff is collapsed.
This diff is collapsed.
File added
File added
File added
#! /bin/bash
filename='q4_in.txt'
while read line; do
read -a num <<< $line
done < $filename
tot=${#num[@]}
sum=0
for i in "${num[@]}"; do
sum=$(echo "scale=2; $sum+$i" | bc)
done
mean=$(echo "scale=2; $sum/$tot" | bc)
echo $mean
for ((i = 0; i<tot; i++)) do
for((j = 0; j<tot-i-1; j++)) do
if (( $(echo "${num[j]} > ${num[$((j+1))]}" |bc -l) ));
then
temp=${num[j]}
num[$j]=${num[$((j+1))]}
num[$((j+1))]=$temp
fi
done
done
if [ $((tot%2)) -eq 0 ]
then
ind=$((tot/2))
a=${num[ind]}
b=${num[$((ind-1))]}
medsum=$(echo "scale=2; $a+$b" | bc)
res=$(echo "scale=2; $medsum/2" | bc)
echo $res
#echo $((((a+b))/2))
else
echo ${num[$((tot/2))]}
fi
Contributions:
CSE Git link:
git@git.cse.iitb.ac.in:sanjnamohan/inLab2.git
q1: Pooja Gayakwad (203050076)
q2: Sanjna Mohan (20305R006)
q3: Snehlata Tadav (203050075)
q4: Manjusree M P (203059007)
References:
https://stackoverflow.com/questions/2564634/convert-absolute-path-into-relative-path-given-a-current-directory-using-bash
https://stackoverflow.com/questions/24112727/relative-paths-based-on-file-location-instead-of-current-working-directory
https://unix.stackexchange.com/questions/273341/obtain-script-current-directory-so-that-i-can-do-include-files-without-relative
https://code-maven.com/bash-shell-relative-path#:~:text=It%20needs%20to%20find%20its,the%20page%20about%20absolute%20path.&text=The%20point%20is%2C%20however%2C%20that,down%20the%20%22data%22%20direcotry.
https://stackoverflow.com/questions/17648033/counting-number-of-directories-in-a-specific-directory
https://www.linuxquestions.org/questions/programming-9/shell-script-help-how-to-pass-a-directory-path-to-the-script-668752/
https://shapeshed.com/unix-wc/#:~:text=To%20count%20the%20number%20of%20folders%20and%20files%20in%20a,wc%20to%20give%20a%20count.
https://stackoverflow.com/questions/24341686/passing-a-path-as-an-argument-to-a-shell-script
https://ubuntu-maryland.org/presentations/reference_bash-cheat.pdf
https://linuxconfig.org/bash-scripting-tutorial-for-beginners#h7-script-execution
https://wiki.bash-hackers.org/syntax/shellvars#special_parameters_and_shell_variables
https://devhints.io/bash
https://linuxhint.com/read_file_line_by_line_bash/
https://linuxhint.com/bash_split_examples/
https://www.geeksforgeeks.org/sorting-the-array-in-bash-using-bubble-sort/
https://tldp.org/LDP/abs/html/mathc.html
https://stackoverflow.com/questions/8654051/how-to-compare-two-floating-point-numbers-in-bash
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment