From 99d0a5cb01946baaaefe40113331f19b9beb4b6d Mon Sep 17 00:00:00 2001 From: lihiekaplun Date: Sun, 9 Feb 2025 14:15:49 +0200 Subject: [PATCH] added my HW --- q1.sh | 16 +++++++++++++++- q2.sh | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 q2.sh diff --git a/q1.sh b/q1.sh index f7ac848..dea80ec 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,15 @@ -This is q1 answer +#!/bin/bash +#a +awk '{count++} END {print count}' aliceinwonderland.txt + +#b +awk '{for(i=2;i<=NF-1;i++) if ($i == "Alice") counter++} END {print counter}' aliceinwonderland.txt + +#c +awk '{for(i=2;i<=NF-1;i++) dic[$i]++} END {for(str in dic) if (dic[str] == 1) print str}' aliceinwonderland.txt +#d +grep -o '[A-Za-z0-9]\+' aliceinwonderland.txt | awk '{dic[$1]++} END {for(word in dic) print word,dic[word]}'|sort -k 2 -n | tail -5 | cut -f 1 -d " " + +#e +awk '{for(i=1;i<=NF;i++) {sum += length($i); count++}} END {print sum/count}' aliceinwonderland.txt + diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..a9a1f2f --- /dev/null +++ b/q2.sh @@ -0,0 +1,16 @@ +#!/bin/bash +#a +sed -n '/Sherlock\|Holmes/p' sherlockholmes.txt | wc -l + +#b +sed -n 's/Sherlock/&/gp; s/Holmes/&/gp' sherlockholmes.txt | wc -l + +#c +sed -E 's/(^)/Hello: /g' sherlockholmes.txt + +#d +sed -nr 's/([A-Z][a-z]{1,})( [A-Z][a-z]{1,})*/Lihie Kaplun/gp' sherlockholmes.txt + +#e +sed 's/(\([^)]*\))/[\1]/g' sherlockholmes.txt +