diff --git a/q1.sh b/q1.sh index f7ac848..463a5df 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,13 @@ -This is q1 answer +#!/bin/bash + +awk 'END {print NR}' aliceinwonderland.txt + +awk '{for (i=1; i<=NF; i++) if ($i=="Alice") c++} END {print c}' aliceinwonderland.txt #I assumed that the qustion asked for each Alice even if it is in the end/beginning of the row else I would have used (i=2; i<=NF-1; i++) + +sed -E 's/\s+/\n/g' aliceinwonderland.txt | awk 'NF {a[$1]++} END {for (k in a) print a[k], k}' | awk '$1==1 {print $2}' + +sed -E 's/\s+/\n/g' aliceinwonderland.txt | awk 'NF {a[$1]++} END {for (k in a) print a[k], k}' | sort -rn | head -n 5 | awk '{print $2}' + +awk '{for(i=1;i<=NF;i++) sum+=length($i); word+=NF} END{print sum/word}' aliceinwonderland.txt #used GPT for the loop in awk + + diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..338aa1d --- /dev/null +++ b/q2.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +sed -n '/Sherlock\|Holmes/p' sherlockholmes.txt | wc -l # used GPT for "-n" + +sed 's/[[:punct:]]//g' sherlockholmes.txt | sed -E 's/\s+/\n/g' | awk 'NF {if ($0 == "Sherlock" || $0 == "Holmes") count++} END {print count}' + +sed -E 's/^.{70}.*$/Long line./' sherlockholmes.txt + +sed -E 's/[[:upper:]][[:alpha:]]+\s[[:upper:]][[:alpha:]]+/Achiad Avigdori/g' sherlockholmes.txt + +sed 's/(/[/g' sherlockholmes.txt | sed 's/)/]/g'