From 8d2b5991684f8442de003f8996a7fc145a2b8735 Mon Sep 17 00:00:00 2001 From: Noam Yaacovi Date: Mon, 10 Feb 2025 17:05:52 +0200 Subject: [PATCH 1/2] added the file with the answers for Q1 --- q1.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/q1.sh b/q1.sh index f7ac848..2128235 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,13 @@ -This is q1 answer +#!bin bash +#1 +awk 'END {print "Total lines: ",NR}' aliceinwonderland.txt +#2 +awk '{count += gsub(/ Alice /, "")} END {print "Occurrences of Alice:", count}' aliceinwonderland.txt +#3 +awk '{for (i=1; i<=NF; i++) freq[$i]++} END {for (word in freq) if (freq[word] == 1) print word}' aliceinwonderland.txt +#4 +awk '{for (i=1; i<=NF; i++) if (length($i) >= 2) freq[$i]++} END {for (word in freq) print word, freq[word]}' aliceinwonderland.txt | sort -k2 -nr | head -5 +#5 +awk '{for (i=1; i<=NF; i++) {total_length += length($i); total_words++}} END {print "Average word length:", total_length/total_words}' aliceinwonderland.txt + + From 8bbda405a6fe9f12a5e699937d3ad61bbede1547 Mon Sep 17 00:00:00 2001 From: Noam Yaacovi Date: Mon, 10 Feb 2025 17:06:12 +0200 Subject: [PATCH 2/2] added the file with the answers for Q2 --- q2.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 q2.sh diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..8fa333b --- /dev/null +++ b/q2.sh @@ -0,0 +1,12 @@ +#!bin bash +#1 +sed -n '/Sherlock\|Holmes/p' sherlockholmes.txt | wc -l +#2 +sed 's/Holmes\|Sherlock/&/g' sherlockholmes.txt | grep -o 'Holmes\|Sherlock' | wc -l +#3 +sed 's/^/Hello: /' sherlockholmes.txt +#4 +sed 's/\b[A-Z][a-z]\{1,\} [A-Z][a-z]\{1,\}\b/Chat GPT/g' filename.txt +#5 +sed 's/([^)]*)/\\[&\\]/g' sherlockholmes.txt +