diff --git a/q1.sh b/q1.sh index f7ac848..f2e955d 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,21 @@ -This is q1 answer +#!/bin/bash +#a +awk 'END {print NR}' aliceinwonderland.txt + +#b +awk '{for(i=1;i<=NF;i++) if ($i == "Alice") count++} END {print count}' aliceinwonderland.txt + +#c + +awk '{for(i=1;i<=NF;i++) words[$i]++} END {for(word in words) if (words[word] == 1) print word}' aliceinwonderland.txt + + +#d +awk '{for (i=1; i<=NF; i++) ($i ~ /[a-zA-Z]/) words[$i]++} END {for (word in words) print words[word], word}' aliceinwonderland.txt | sort -n | tail -5 + +#e +awk '{for (i=1; i<=NF; i++) {sum_length+=length($i); words_counter++}} END {print sum_length/words_counter}' aliceinwonderland.txt + + + + diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..474d197 --- /dev/null +++ b/q2.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +#a +sed -n '/Sherlock\|Holmes/p' sherlockholmes.txt | wc -l + +#b +sed -n 's/[^a-zA-Z]\(Sherlock\|Holmes\)[^a-zA-Z]/\n&\n/gp' sherlockholmes.txt | grep -o 'Sherlock\|Holmes' | wc -l + +#c +sed 's/^/Hello: /' sherlockholmes.txt + +#d +sed -E 's/\b[A-Z]{1}[a-z]+ [A-Z]{1}[a-z]+\b/Jonathan_Weil/g' sherlockholmes.txt + +#e +sed -E 's/\(([^()]*)\)/[\1]/g' sherlockholmes.txt +