From 9731719d2b37534a286c42c2323ec998802f5649 Mon Sep 17 00:00:00 2001 From: Niv-Drori-RUNI Date: Sat, 8 Feb 2025 16:18:37 +0200 Subject: [PATCH 1/2] solution for question 1 --- q1.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/q1.sh b/q1.sh index f7ac848..9d5867a 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,19 @@ -This is q1 answer +#!/bin/bash + +echo " Question 1 part a:" +awk 'END{print NR}' aliceinwonderland.txt +echo "The number of rows is 3325" + +echo "Question 1 part b:" +awk '{for(i=1;i<=NF;i++) {if($i ~ /^Alice$/) count++}} END {print count}' aliceinwonderland.txt +echo "The number of times the word Alice (with an whitespace before and after the word) is shown in the text is 212" + +echo "Question 1 part c:" +awk '{for (i=1; i<=NF; i++) {word=tolower($i); gsub(/[^a-z]/, "", word); if (word != "") words[word]++}} END {for (w in words) if (words[w] == 1) print w}' aliceinwonderland.txt + +echo "Question 1 part d:" +for word in $(cat aliceinwonderland.txt) ; do echo $word; done | awk '! /([[:punct:]]|[[:space:]])/' | awk '{a[$1]++}END {for (k in a) print a[k], k}' | sort -n -r | head -n 5 + +echo "Question 1 part e:" +awk '{ for (i = 1; i <= NF; i++) { word = $i; gsub(/[^a-zA-Z]/, "", word); if (word != "") { total_length += length(word); word_count++ } } } END { if (word_count > 0) print total_length / word_count; else print "No valid words found" }' aliceinwonderland.txt + From 66e7992db19e87f7e272bf0a3e1df7270b8c0f43 Mon Sep 17 00:00:00 2001 From: Niv-Drori-RUNI Date: Sat, 8 Feb 2025 16:18:55 +0200 Subject: [PATCH 2/2] solution for question 2 --- q2.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 q2.sh diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..a7418d5 --- /dev/null +++ b/q2.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +echo "Question 2 part a:" +sed -E -n '/Holmes|Sherlock/p' sherlockholmes.txt | wc -l +echo "463 lines" + +echo "Question 2 part b:" +sed -E -n '/Holmes|Sherlock/p' sherlockholmes.txt | grep -E -o 'Holmes|Sherlock' | wc -l +echo "554 times" + +echo "Question 2 part c:" +sed -E 's/^/Hello:/' sherlockholmes.txt + +echo "Question 2 part d:" +sed -E 's/[A-Z][a-z]{1,}\s[A-Z][a-z]{1,}/Niv Drori/g' sherlockholmes.txt + +echo "Question 2 part e:" +sed -E 's/\(([^)]*)\)/[\1]/g' sherlockholmes.txt +