Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion q1.sh
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
This is q1 answer
echo "question 1.a"
awk '{print NR}' aliceinwonderland.txt | tail -n 1
echo: "3325 rows"

echo "question 1.b"
awk '{for(i=1;i<=NF;i++) {if($i ~ /^Alice$/) count++}} END {print count}' aliceinwonderland.txt
echo "212 times, note: in order to find only with spaces before and after, I searched for exactly the word Alice, with no extra characters"


echo "question 1.c"
awk '{for(i=1; i<=NF; i++) {gsub(/[^[:alpha:]]/, "", $i) words[$i]++}} END {for(word in words) {if(words[word] == 1) count++}} END {print count}' aliceinwonderland.txt
echo "1526 words, note that I removed punctuation, another approach is to look for words containing only alphabetic characters if($i ~ /^[[:alpha:]]+$/)"

echo "question 1.d"
awk '{for(i=1;i<=NF;i++) if($i ~ /^[[:alpha:]]+$/) print $i}' aliceinwonderland.txt | sort | uniq -c | sort -k 1 -h | tail -n 5 | awk '{print $2}'
echo "of, a, and, to, the"

echo "question 1.e"
awk '{for(i=1; i<=NF; i++) {if($i ~ /^[[:alpha:]]+$/) {lengths += length($i);count++;}}} END {print lengths / count}' aliceinwonderland.txt
echo "3.84393"
17 changes: 17 additions & 0 deletions q2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
echo "question 2.a"
sed -n '/Holmes\|Sherlock/p' sherlockholmes.txt | wc -l
echo "463 lines"

echo "question 2.b"
sed -n '/Holmes\|Sherlock/p' sherlockholmes.txt | grep -Eo 'Sherlock|Holmes' | wc -l
echo "554 times"

echo "question 2.c"
sed -E 's/^/Hello: /' sherlockholmes.txt

echo "question 2.d"
sed -E 's/[A-Z][a-z]+\s[A-Z][a-z]+/Idan/' sherlockholmes.txt

echo "question 2.e"
sed -E 's/\(/[/g' sherlockholmes.txt | sed -E 's/\)/]/g'