diff --git a/q1.sh b/q1.sh index f7ac848..346cf6d 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,15 @@ -This is q1 answer +#!/bin/bash +#1a +awk '{print NR}' aliceinwonderland.txt | tail -1 + +#1b +awk '/ Alice /{print NR}' aliceinwonderland.txt | wc -l + +#1c +awk '{for (i=1; i<=NF; i++) {gsub(/[^a-zA-Z0-9]/, "", $i); print $i}}' aliceinwonderland.txt | sort -h | uniq -c | awk '/1/{print $2}' | wc -l + +#1d +awk '{for (i=1; i<=NF; i++) {gsub(/[^a-zA-Z0-9]/, "", $i); print $i}}' aliceinwonderland.txt | sort -h | uniq -c | sort -h | tail -6 | sed '5d' | awk '{print $2}' + +#1e +awk '{total_words += NF; for (i=1; i<=NF; i++) total_length += length($i)} END {print total_length / total_words}' aliceinwonderland.txt diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..f1fb89a --- /dev/null +++ b/q2.sh @@ -0,0 +1,15 @@ +#!/bin/bash +#2a +sed -n '/Sherlock\|Holmes/p' sherlockholmes.txt | wc -l + +#2b +grep -o 'Sherlock\|Holmes' sherlockholmes.txt | sed -n '$=' + +#2c +sed 's/^/Hello:/' sherlockholmes.txt + +#2d +sed 's/[A-Z][a-z]\+ [A-Z][a-z]\+/Itamar Saacks/g' sherlockholmes.txt + +#2e +sed -E 's/\((.*)\)/[\1]/g' sherlockholmes.txt