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
14 changes: 13 additions & 1 deletion q1.sh
Original file line number Diff line number Diff line change
@@ -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


11 changes: 11 additions & 0 deletions q2.sh
Original file line number Diff line number Diff line change
@@ -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'