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
19 changes: 18 additions & 1 deletion q1.sh
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
This is q1 answer
#!/bin/bash

nr=$(awk 'END{print NR}' aliceinwonderland.txt)
echo "Number of rows: ${nr}"

alice_count=$(awk 'BEGIN{c=0} / Alice /{c+=1} END{print c}' aliceinwonderland.txt)
echo "Alice count: ${alice_count}"

word_count=$(awk '{total+=NF} END{print total}' aliceinwonderland.txt)
echo "Total words count: ${word_count}"

top_5=$(cat aliceinwonderland.txt | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | awk '{for(i=1; i<=NF; i++) if ($i ~ /^[[:alpha:]]+$/) dict[$i]++} END{ for(word in dict) print dict[word], word}' | sort -nr -t' ' -k1 | head -n5 )

echo "Top 5 most repeated words:"
echo "${top_5}"

avg=$(cat aliceinwonderland.txt | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | awk '{for(i=1; i<=NF; i++) if ($i ~ /^[[:alpha:]]+$/) {total_length+=length($i); total_words++}} END{print total_length/total_words}')
echo "Average word length: ${avg}"
13 changes: 13 additions & 0 deletions q2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!bun/bash

a=$(sed -n -E '/Sherlock | Holmes/p' sherlockholmes.txt | wc -l)
echo "a) Number of rows conatining Sherlock or Holmes: ${a}"

b=$(sed -E 's/(sherlock|holmes)/\n\1\n/Ig' sherlockholmes.txt | sed -E -n '/^(sherlock|holmes$)/Ip' | wc -l)
echo "b) Count of sherlock and holmes: ${b}"

echo "c) sed -E 's/^.{70,}$/Long Line/' sherlockholmes.txt"

echo "d) sed -E 's/ ([A-Z]{1}[a-z]{1,} ){2}/ Noya Weiss /g' sherlockholmes.txt"

echo "e) sed -E 's/\((.+)\)/\[\1\]/' sherlockholmes.txt"