From 19fde330167f85bed99a1a9adc0508305ad6ffa7 Mon Sep 17 00:00:00 2001 From: Tamar-katzir Date: Sun, 9 Feb 2025 10:27:43 +0000 Subject: [PATCH] q1 and q2 --- q1.sh | 14 +++++++++++++- q2.sh | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 q2.sh diff --git a/q1.sh b/q1.sh index f7ac848..253292c 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,13 @@ -This is q1 answer +awk '{print NR}' aliceinwonderland.txt | tail -1 +#3325 +awk '{count += gsub(/ Alice /, "")} END {print count+0}' aliceinwonderland.txt +#155 +awk '{gsub(/^[[:punct:]]|[[:punct:]]$/, ""); a[$0]++} END{for (w in a) print w,a[w]}' RS='[[:space:]]' aliceinwonderland.txt | awk '$2==1 {print $1}' +awk '{gsub(/[[:punct:]]/, "")} 1' RS='[[:space:]]' aliceinwonderland.txt | sort | uniq -c | sort | tail -6 | head -5 + # 498 she + # 610 a + # 717 to + # 774 and + # 1514 the +awk '{gsub(/[[:punct:]]/, "")} 1' RS='[[:space:]]' aliceinwonderland.txt | awk '/./' | awk '{sum += length($0)} END {print sum / NR}' +#4.08109 diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..04af3c1 --- /dev/null +++ b/q2.sh @@ -0,0 +1,7 @@ +sed -n '/\(Sherlock\|Holmes\)/p' sherlockholmes.txt | wc -l +#463 +grep -o '\b\(Sherlock\|Holmes\)\b' sherlockholmes.txt | sed -n '$=' +#554 +sed -i -e 's/^/Hello:/' sherlockholmes.txt +sed -r 's/([A-Z][a-z]{2,}) ([A-Z][a-z]{2,})/Tamar Katzir/g' sherlockholmes.txt +sed -rn -i 's/\(([^)]*)\)/[\1]/gp; t; p' sherlockholmes.txt