From b1d311619e625be913854a8e18dba57a9f5ed1c0 Mon Sep 17 00:00:00 2001 From: Yarden Safran Date: Tue, 27 Jan 2026 15:32:30 +0200 Subject: [PATCH] added my solutions --- q1.sh | 16 +++++++++++++++- q2.sh | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 q2.sh diff --git a/q1.sh b/q1.sh index f7ac848..6c820eb 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,15 @@ -This is q1 answer +#A +cat aliceinwonderland.txt | awk '{print NR}'|tail -1 + + +#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++) dict[$i]++} END {for (k in dict) if(dict[k]==1) print k}' aliceinwonderland.txt + +#D +awk '{for(i=1; i<=NF; i++) dict[$i]++} END {for (k in dict) if (k != "" && k != " ") print dict[k], k}' aliceinwonderland.txt | sort -n | tail -5 + +#E +awk '{(total_words+=NF); for(i=1; i<=NF; i++) (total=total+length($i))} END {print(total/total_words)}' aliceinwonderland.txt diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..6286bb5 --- /dev/null +++ b/q2.sh @@ -0,0 +1,10 @@ +#A +sed -En '/Sherlock|Holmes/p' sherlockholmes.txt |wc -l +#B +sed -E 's/Sherlock|Holmes/\n&\n/g' sherlockholmes.txt|sed -En '/Sherlock|Holmes/p'|wc -l +#C +sed -E 's/^.{70,}$/Long Line/p' sherlockholmes.txt +#D +sed -E 's/([A-Z][a-z]+) ([A-Z][a-z]+)/Yarden Safran/g' sherlockholmes.txt +#E +sed -E 's/\((.*)\)/[\1]/g' sherlockholmes.txt