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
11 changes: 11 additions & 0 deletions q1.sh
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
This is q1 answer
awk 'END {print NR}' aliceinwonderland.txt
#prints the numbers of lines in the text
awk '{for(i=1; i<=NF; i++) if ($i=="Alice") count++} END {print count}' file.txt
#finds how many times the word alice is in the book
awk '{for (i=1; i<=NF; i++) a[$i]++} END {for (k in a) if (a[k]==1) print k}' aliceinwonderland.txt
#returns words that only apears once
awk '{for (i=2; i<=NF-1; i++) a[$i]++} END {for (k in a) print a[k], k}' aliceinwonderland.txt | sort -n | tail -5 | cut -d " " -f 2
#return 5 most common words
awk '{for (i=1; i<=NF; i++) {s+=length($i); count++}} END {print s/count}' aliceinwonderland.txt
#prints the avrage word length

10 changes: 10 additions & 0 deletions q2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sed -E -n '/(Sherlock|Holmes)/p' sherlockholmes.txt | wc -l
#counts all lines with the word sherlock or homes
sed -E -n '/(Sherlock|Holmes)/p' sherlockholmes.txt | grep -o 'Sherlock\|Holmes'| wc -l
#finds how many times the words aherlock and holmes appear
sed -E 's/^/Hello: /g' sherlockholmes.txt
#adds hello: to every line
sed -E 's/[A-Z]{1}[a-z]+\s[A-Z]{1}[a-z]+/sahar/g' sherlockholmes.txt
#replace every name with my name
sed -E 's/\((.*)\)/[\1]/g' sherlockholmes.txt
#replace all () with [] if in the same line