diff --git a/q1.sh b/q1.sh index f7ac848..44b1462 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,18 @@ -This is q1 answer +#!/bin/bash + +nr=$(awk 'END{print NR}' aliceinwonderland.txt) +echo "Number of rows: ${nr}" + +alice_count=$(awk 'BEGIN{c=0} / Alice /{c+=1} END{print c}' aliceinwonderland.txt) +echo "Alice count: ${alice_count}" + +word_count=$(awk '{total+=NF} END{print total}' aliceinwonderland.txt) +echo "Total words count: ${word_count}" + +top_5=$(cat aliceinwonderland.txt | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | awk '{for(i=1; i<=NF; i++) if ($i ~ /^[[:alpha:]]+$/) dict[$i]++} END{ for(word in dict) print dict[word], word}' | sort -nr -t' ' -k1 | head -n5 ) + +echo "Top 5 most repeated words:" +echo "${top_5}" + +avg=$(cat aliceinwonderland.txt | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | awk '{for(i=1; i<=NF; i++) if ($i ~ /^[[:alpha:]]+$/) {total_length+=length($i); total_words++}} END{print total_length/total_words}') +echo "Average word length: ${avg}" diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..0dbe1b1 --- /dev/null +++ b/q2.sh @@ -0,0 +1,13 @@ +#!bun/bash + +a=$(sed -n -E '/Sherlock | Holmes/p' sherlockholmes.txt | wc -l) +echo "a) Number of rows conatining Sherlock or Holmes: ${a}" + +b=$(sed -E 's/(sherlock|holmes)/\n\1\n/Ig' sherlockholmes.txt | sed -E -n '/^(sherlock|holmes$)/Ip' | wc -l) +echo "b) Count of sherlock and holmes: ${b}" + +echo "c) sed -E 's/^.{70,}$/Long Line/' sherlockholmes.txt" + +echo "d) sed -E 's/ ([A-Z]{1}[a-z]{1,} ){2}/ Noya Weiss /g' sherlockholmes.txt" + +echo "e) sed -E 's/\((.+)\)/\[\1\]/' sherlockholmes.txt"