Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion q1.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions q2.sh
Original file line number Diff line number Diff line change
@@ -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<NF;i++) if($i ~ /^[A-Z][a-zA-Z]{1,}$/ && $(i+1) ~ /^[A-Z][a-zA-Z]{1,}$/) {$i="ido"; $(i+1)="onn"}}1' sherlockholmes.txt

awk '{gsub(/\(.*\)/, "[" substr($0, index($0,$1)) "]"); print}' sherlockholmes.txt