diff --git a/q1.sh b/q1.sh index f7ac848..549c0c3 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,10 @@ -This is q1 answer +awk '{print NR}' aliceinwonderland.txt | tail -1 + +awk '{n += gsub(/ Alice /, "")} END {print n}' aliceinwonderland.txt + +awk '{for(i=1;i<=NF;i++) count[$i]++} END {for(word in count) if(count[word] == 1) print word}' aliceinwonderland.txt + + +awk '{for(i=1;i<=NF;i++) count[$i]++} END {for(word in count) print count[word], word}' aliceinwonderland.txt | sort -nr | head -n 5 + +awk '{for(i=1;i<=NF;i++) sum+=length($i); count+=NF} END {print sum/count}' aliceinwonderland.txt diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..242ccda --- /dev/null +++ b/q2.sh @@ -0,0 +1,9 @@ +awk '/Sherlock|Holmes/ {count++} END {print count}' sherlockholmes.txt + +awk '{count += gsub(/Sherlock|Holmes/, "")} END {print count}' sherlockholmes.txt + +awk '{print "Hello:", $0}' sherlockholmes.txt + +awk '{for(i=1;i