From 7f5356901adff8f90d99f7217b401d728f560391 Mon Sep 17 00:00:00 2001 From: noaasulin Date: Fri, 7 Feb 2025 16:49:39 +0200 Subject: [PATCH 1/2] Added my answer to question 1 --- q1.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/q1.sh b/q1.sh index f7ac848..05e3b1f 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,19 @@ -This is q1 answer +#!/bin/bash + +#A +awk '{print NR}' aliceinwonderland.txt | tail -1 + + +#B +awk '{for (i=1 ; i<=NF ; i++) if($i == "Alice") count++} END {print count}' aliceinwonderland.txt + + +#C +awk '{a[$1]++} END {for(k in a) print a[k], k}' aliceinwonderland.txt | sort -n | awk '$1 ==1' + +#D +awk '{for (i=1 ; i<=NF ; i++) if( $i != " ") word[$i]++} END {for (w in word) print word[w], w}' aliceinwonderland.txt | sort -nr | head -6 | sed '2d' + +#E +awk '{for (i=1; i<=NF; i++) {total_length += length($i); total_words++}} END {printf "Average length: %.2f\n", total_length / total_words}' aliceinwonderland.txt + From 7df4aa38b485552af3ae36c9bc501cd390c9279f Mon Sep 17 00:00:00 2001 From: noaasulin Date: Fri, 7 Feb 2025 16:52:04 +0200 Subject: [PATCH 2/2] Added my answer to question 2 --- q2.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 q2.sh diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..b47f1b3 --- /dev/null +++ b/q2.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +#A +sed -n /Holmes|Shelock/p sherlockholmes.txt +#B +sed -n /Holmes|Shelock/p sherlockholmes.txt | wc -l +#C +sed s/^/Hello: / sherlockholmes.txt +#D +sed -E 's/\b[A-Z][a-z]{1,} [A-Z][a-z]{1,}\b/Noa Asulin/g' sherlockholmes.txt +#E +sed -E 's/\(/\[/g' sherlockholmes.txt | sed -E 's/\)/\]/g' +