From 01a3634e6003aff153e6e5684115f6917a27d24a Mon Sep 17 00:00:00 2001 From: Nadav Date: Sun, 25 Jan 2026 19:06:59 +0200 Subject: [PATCH] Added Q1 and Q2 answers for Ex10 - Nadav Halpern --- Q1.sh | 16 ++++++++++++++++ Q2.sh | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Q1.sh create mode 100644 Q2.sh diff --git a/Q1.sh b/Q1.sh new file mode 100644 index 0000000..e414ae6 --- /dev/null +++ b/Q1.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +### A +awk ' {print NR} ' aliceinwonderland.txt | tail -1 + +### B +awk '/ Alice / {count ++} END {print count}' aliceinwonderland.txt + +### C +awk '{for (i=1; i<=NF; i++) count[$i]++} END {for (word in count) if (count[word] ==1) print word}' aliceinwonderland.txt + +### D +awk '{for (i=1; i<=NF; i++) count[$i]++ } END { for (word in count) print word, count[word] }' aliceinwonderland.txt | sort -k2n | tail -5 + +### E +awk '{for (i=1; i<=NF; i++) count[$i]++ } END { for (word in count) print word, count[word] }' aliceinwonderland.txt | awk ' {sum_chars += length($1) * $2; total_words += $2} END { print sum_chars / total_words}' diff --git a/Q2.sh b/Q2.sh new file mode 100644 index 0000000..e414ae6 --- /dev/null +++ b/Q2.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +### A +awk ' {print NR} ' aliceinwonderland.txt | tail -1 + +### B +awk '/ Alice / {count ++} END {print count}' aliceinwonderland.txt + +### C +awk '{for (i=1; i<=NF; i++) count[$i]++} END {for (word in count) if (count[word] ==1) print word}' aliceinwonderland.txt + +### D +awk '{for (i=1; i<=NF; i++) count[$i]++ } END { for (word in count) print word, count[word] }' aliceinwonderland.txt | sort -k2n | tail -5 + +### E +awk '{for (i=1; i<=NF; i++) count[$i]++ } END { for (word in count) print word, count[word] }' aliceinwonderland.txt | awk ' {sum_chars += length($1) * $2; total_words += $2} END { print sum_chars / total_words}'