From 075052bcf3b46a919f88f753cee306c11e24528f Mon Sep 17 00:00:00 2001 From: jonathan_weil Date: Sun, 9 Feb 2025 20:05:08 +0200 Subject: [PATCH 1/2] updated q1.sh - with my answers to question 1 --- q1.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/q1.sh b/q1.sh index f7ac848..f2e955d 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,21 @@ -This is q1 answer +#!/bin/bash +#a +awk 'END {print NR}' aliceinwonderland.txt + +#b +awk '{for(i=1;i<=NF;i++) if ($i == "Alice") count++} END {print count}' aliceinwonderland.txt + +#c + +awk '{for(i=1;i<=NF;i++) words[$i]++} END {for(word in words) if (words[word] == 1) print word}' aliceinwonderland.txt + + +#d +awk '{for (i=1; i<=NF; i++) ($i ~ /[a-zA-Z]/) words[$i]++} END {for (word in words) print words[word], word}' aliceinwonderland.txt | sort -n | tail -5 + +#e +awk '{for (i=1; i<=NF; i++) {sum_length+=length($i); words_counter++}} END {print sum_length/words_counter}' aliceinwonderland.txt + + + + From 042b04d3aa474e3621b20a3401daa6e4ad99be5f Mon Sep 17 00:00:00 2001 From: jonathan_weil Date: Sun, 9 Feb 2025 20:05:44 +0200 Subject: [PATCH 2/2] added q2.sh - with my answers to question 2 --- q2.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 q2.sh diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..474d197 --- /dev/null +++ b/q2.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +#a +sed -n '/Sherlock\|Holmes/p' sherlockholmes.txt | wc -l + +#b +sed -n 's/[^a-zA-Z]\(Sherlock\|Holmes\)[^a-zA-Z]/\n&\n/gp' sherlockholmes.txt | grep -o 'Sherlock\|Holmes' | wc -l + +#c +sed 's/^/Hello: /' sherlockholmes.txt + +#d +sed -E 's/\b[A-Z]{1}[a-z]+ [A-Z]{1}[a-z]+\b/Jonathan_Weil/g' sherlockholmes.txt + +#e +sed -E 's/\(([^()]*)\)/[\1]/g' sherlockholmes.txt +