diff --git a/q1.sh b/q1.sh index f7ac848..0f78de7 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,29 @@ -This is q1 answer +#!/bin/bash +#q1a +cat books/aliceinwonderland.txt | awk '{print NR}' | tail -1 +3325 + +#q1b +cat books/aliceinwonderland.txt | awk '/ Alice / {print NR,NF, /bin/bash} ' | awk '{print NR}' | tail -n 1 +155 + +#q1c +cat books/aliceinwonderland.txt | awk '{ for (i=1; i<=NF; i++) c[]++} END { for( w in c) if (c[w]==1) print w } ' +3860 + +#q1d + +cat books/aliceinwonderland.txt | awk '{for( i=1; i<=NF; i++) print } ' | sort | uniq -c | sort -n | tail -6 + 459 of + 569 a + 662 and + 669 to + 849 + 1400 the + +#q1e +words=$(cat books/aliceinwonderland.txt | awk '{ words+=NF } END { print words} ') +char=$( cat books/aliceinwonderland.txt | awk ' {for (i=1; i<=NF; i++) chars+=length($i) } END { print chars} ') +result=$((char/words)) +echo $result +4 diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..60503ec --- /dev/null +++ b/q2.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +#q2a +cat books/sherlockholmes.txt | sed -n '/Sherlock\|Holmes/p' | awk '{print NR, /bin/bash}' | cut -f 1 -d | tail -1 +463 + +#q2b +cat books/sherlockholmes.txt | sed -n '/Sherlock\|Holmes/p' | grep Holmes |Sherlock | wc -l +220 + + +#q2c +cat books/sherlockholmes.txt | sed 's/^.\{70,\}$/Long Line/' + +#q2d + +cat books/sherlockholmes.txt | sed 's/[A-Z][a-z]*\([[:space:]][A-Z][a-z]*\)\{1,\}/Omer/' + +#q2e +cat books/sherlockholmes.txt | sed -E 's/\(([^)]*)\)/[\1]/g'