diff --git a/q1.sh b/q1.sh index f7ac848..05e3b1f 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,19 @@ -This is q1 answer +#!/bin/bash + +#A +awk '{print NR}' aliceinwonderland.txt | tail -1 + + +#B +awk '{for (i=1 ; i<=NF ; i++) if($i == "Alice") count++} END {print count}' aliceinwonderland.txt + + +#C +awk '{a[$1]++} END {for(k in a) print a[k], k}' aliceinwonderland.txt | sort -n | awk '$1 ==1' + +#D +awk '{for (i=1 ; i<=NF ; i++) if( $i != " ") word[$i]++} END {for (w in word) print word[w], w}' aliceinwonderland.txt | sort -nr | head -6 | sed '2d' + +#E +awk '{for (i=1; i<=NF; i++) {total_length += length($i); total_words++}} END {printf "Average length: %.2f\n", total_length / total_words}' aliceinwonderland.txt + diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..b47f1b3 --- /dev/null +++ b/q2.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +#A +sed -n /Holmes|Shelock/p sherlockholmes.txt +#B +sed -n /Holmes|Shelock/p sherlockholmes.txt | wc -l +#C +sed s/^/Hello: / sherlockholmes.txt +#D +sed -E 's/\b[A-Z][a-z]{1,} [A-Z][a-z]{1,}\b/Noa Asulin/g' sherlockholmes.txt +#E +sed -E 's/\(/\[/g' sherlockholmes.txt | sed -E 's/\)/\]/g' +