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
#!/bin/bash
#a
awk 'END {print NR}' aliceinwonderland.txt
#3325
#b
awk '{for(i=2;i<NF;i++) if ($i == "Alice") count++} END {print count}' aliceinwonderland.txt

#other option
awk '{count += gsub(/ Alice /, "")} END {print count}' aliceinwonderland.txt
#155
#c
cat aliceinwonderland.txt | awk '{for (i=2; i<NF; i++) words[$i]++} END {for (word in words) if (words[word] == 1) print word}'
#d
cat aliceinwonderland.txt | awk '{for (i=2; i<NF; i++) words[$i]++} END {for (word in words) print words[word], word}'c| sort -nr | head -5
#other option wich gives diffrent count of words but same words
grep -o '\S\+' aliceinwonderland.txt | awk '{ words[$1]++ } END {for (word in words) print words[word] , word}' | sort -n | tail -5

#e
cat aliceinwonderland.txt | awk '{for (i=1; i<=NF; i++) {sum+=length($i); total_words++}} END {print sum/total_words}'
#4.37187
15 changes: 15 additions & 0 deletions q2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
#a
sed -En '/Sherlock|Holmes/p' sherlockholmes.txt | wc -l
#463
#b
sed -n '{/Holmes/p; /Sherlock/p}' sherlockholmes.txt | wc -l
#553
#c
sed -E 's/^/Hello: /' sherlockholmes.txt
#d
sed -n 's/\b[A-Z][a-z]\{2,\} [A-Z][a-z]\{2,\}\b/shiraz ben shoshan/gp' sherlockholmes.txt
#e
sed -nE 's/\(([^()]*)\)/[\1]/gp' sherlockholmes.txt