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
16 changes: 15 additions & 1 deletion q1.sh
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
This is q1 answer
#a
awk 'END {print NR}' aliceinwonderland.txt
#works also: awk '{print $0}' aliceinwonderland.txt | wc -l

#b
awk '{for(i=2;i<NF;i++) if ($i=="Alice") count++} END {print count}' aliceinwonderland.txt

#c
awk '{for (i=2; i<NF; i++) words[$i]++;} END {for (w in words) if (words[w] == 1) print w;}' aliceinwonderland.txt

#d
awk '{for (i=2; i<NF; i++) words[$i]++;} END {for (w in words) print words[w], w;}' aliceinwonderland.txt | sort -h | tail -5

#e
awk '{for (i=2; i<NF; i++) {wordsLength += length($i); sumWords++;}} END {avgLength = wordsLength / sumWords; print avgLength;}' aliceinwonderland.txt
11 changes: 11 additions & 0 deletions q2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#a
sed -En '/Sherlock|Holmes/p' sherlockholmes.txt | wc -l
#b
sed -n 's/Sherlock/&\n/gp; s/Holmes/&\n/gp' sherlockholmes.txt | grep -Eo "Sherlock|Holmes" | wc -l
#c
sed 's/^/Hello:/' sherlockholmes.txt
#d
sed -E 's/[A-Z][a-z]{1,} [A-Z][a-z]{1,}/Lia Korman/g' sherlockholmes.txt
#e
sed -n 's/(/[/g; s/)/]/g; p' sherlockholmes.txt