diff --git a/q1.sh b/q1.sh index f7ac848..5f0a2be 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,20 @@ -This is q1 answer +#!/bin/bash +#a +echo "number of rows:" +awk '{print NR}' aliceinwonderland.txt | tail -n 1 +#b +echo "number of times Alice appear:" +awk '/ Alice / {count++} END {print count}' aliceinwonderland.txt +#c +echo "words appear 1 times:" +cat aliceinwonderland.txt | tr -dc '[:alpha:][:space:]' | tr -s ' ' '\n' | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -rn | awk '$1 == 1 {print $2}' + +#d +echo " 5 most freuqency words:" +cat aliceinwonderland.txt | tr -dc '[:alpha:][:space:]' | tr -s ' ' '\n' | tr '[:upper:]' '[:lower:]' |sort | uniq -c | sort -rn | head -n 5 + +#e +echo "the average:" +cat aliceinwonderland.txt | tr -d '[:punct:]' | tr -s ' ' '\n' | awk '{count += length($0)}{words += NF} END {print count/words}' + +#assitents in ai to understand how to keep in the words only alpha and space - tr -dc '[:alpha:][:space:]' diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..7720bc3 --- /dev/null +++ b/q2.sh @@ -0,0 +1,11 @@ +#!/bin/bash +#a +sed -rn '/Sherlock|Holmes/p' sherlockholmes.txt | wc -l +#b +cat sherlockholmes.txt | tr -s ' ' '\n' | tr -dc '[:alpha:][:space:]' |sed -rn '/^Sherlock$|^Holmes$/p' | wc -l +#c +sed -E -i 's/^.{71,}$/Long line/' sherlockholmes.txt +#d +sed -E -i 's/\b[[:upper:]][[:alpha:]]+\b/Maya/g' sherlockholmes.txt +#e +sed -E -i 's/\(([^)]*)\)/[\1]/g' sherlockholmes.txt