diff --git a/q1.sh b/q1.sh index f7ac848..c231b48 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,24 @@ -This is q1 answer +#!/bin/bash +#a) +awk '{print "Num of rows:" NR, $0}' alice.txt | tail -n 1 | cut -d " " -f 1,2,3,4 + +#b) +cat alice.txt | tr -s '[:space:]' '\n' | awk '$0=="Alice"{count++} END{print "Num of Alice apperance:" count}' + +#c) + +awk '{for (i=1;i<=NF;i++) count[$i]++} END {for (w in count) if (count[w]==1) print w}' alice.txt | tr -d '[:punct:]' | head -n 10 + +#d) + +awk '{for (i=1;i<=NF;i++) count[$i]++} END {for (w in count) print w,count[w]}' alice.txt | sort -h | awk '{sum[$1]+=$2} END {for (w in sum) print sum[w],w}' | sort -n | tail -n 5 + +#e) + +sum_of_length=$(awk '{for (i=1;i<=NF;i++) print $i}' alice.txt | sort | tr -d '[:punct:]' | awk '{print tolower($1)}' | awk '{print length($1)}' | awk '{sum+=$1} END{print sum}') + +count_of_all_words=$(awk '{for (i=1;i<=NF;i++) print $i}' alice.txt | wc -l) + +result=$(echo "scale=2; ${sum_of_length} / ${count_of_all_words}" | bc) + +echo 'the avg word length is:' ${result} diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..4c72022 --- /dev/null +++ b/q2.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +#a) +sed -E -n '/(Sherlock|Holmes)/p' sherlockholmes.txt | wc -l + +#b) + +sed -E 's/(Sherlock|Holmes)/\n\1\n/' sherlockholmes.txt | sed -n -E '/(Sherlock|Holmes)/p' | wc -l + +#c) + +sed -E 's/^.{70,}$/Long Line/' sherlockholmes.txt + +#d) + +sed -E 's/[A-Z]+[a-z]+[[:space:]][A-Z]+[a-z]+/Ily Glazer/g' sherlockholmes.txt + +#e) + +sed -n -E 's/\((.+)\)/[\1]/gp' sherlockholmes.txt