diff --git a/q1.sh b/q1.sh index f7ac848..9a67888 100644 --- a/q1.sh +++ b/q1.sh @@ -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 + diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..c242408 --- /dev/null +++ b/q2.sh @@ -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