From 070c0c7ac12483f0f4880304f875ac021c76c32b Mon Sep 17 00:00:00 2001 From: Almog Maman Date: Sat, 24 Jan 2026 19:49:01 +0000 Subject: [PATCH] Homework 10 solutions: q1 (Alice) and q2 (Sherlock) --- q1.sh | 8 +++++++- q2.sh | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 q2.sh diff --git a/q1.sh b/q1.sh index f7ac848..598b60d 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,7 @@ -This is q1 answer +#!/bin/bash +awk 'END {print NR}' aliceinwonderland.txt +awk '{for (i=1; i<=NF; i++) if ($i=="Alice") count++} END { print count }' aliceinwonderland.txt +sed -E 's/[[:space:]]+/\n/g' aliceinwonderland.txt | awk 'NF {a[$1]++} END {for (k in a) if(a[k]==1) print k}' +sed -E 's/[[:space:]]+/\n/g' aliceinwonderland.txt | awk 'NF {a[$1]++} END {for (k in a) print a[k], k}' | sort -nr | head -5 +awk '{for (i=1; i<=NF; i++) {sum += length($i); cnt++}} END{print sum/cnt}' aliceinwonderland.txt +# I learned how to use a for-loop in awk with the help of ChatGPT diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..1ff91d3 --- /dev/null +++ b/q2.sh @@ -0,0 +1,5 @@ +sed -nE '/(Holmes|Sherlock)/p' sherlockholmes.txt | wc -l +sed -E 's/[[:punct:]]/ /g; s/[[:space:]]+/\n/g' sherlockholmes.txt | sed -nE '/^(Sherlock|Holmes)$/p' | wc -l +sed -E '/^.{70,}$/c\Long line' sherlockholmes.txt +sed -E 's/([A-Z]){1}([a-z])+ ([A-Z]){1}([a-z])+/Almog Maman/g' sherlockholmes.txt +sed 's/(/[/g' sherlockholmes.txt | sed 's/)/]/g'