diff --git a/q1.sh b/q1.sh index f7ac848..31b2056 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,14 @@ -This is q1 answer +#!/bin/bash + +awk END'{print NR}' aliceinwonderland.txt + +grep -o " Alice " aliceinwonderland.txt | awk END'{print NR}' + +grep -oE ' [[:alpha:]]+ ' aliceinwonderland.txt | sort | uniq -c | awk '$1==1' | wc -l + +grep -oE ' [[:alpha:]]+ ' aliceinwonderland.txt | sort | uniq -c | sort -nr | awk ' NR==1 , NR==5 {print NR, $2}' + +grep -oE ' [[:alpha:]]+ ' aliceinwonderland.txt | grep -oE ' [[:alpha:]]+ ' aliceinwonderland.txt | awk '{sum+=length($0) ; count++} END{print sum/count}' + + + diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..5b15a2c --- /dev/null +++ b/q2.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +sed -nE '/Sherlock | Holmes/p' sherlockholmes.txt | wc -l +#searching for 2 patterns in a line + +grep -oE '[[:alpha:]]+' sherlockholmes.txt | sort | uniq -c | sed -nE '/Sherlock|Holmes/p' +#number of the words Sherlock or Holmes apear in the text. + +sed -E '/^.{70,}$/c\Long Line' sherlockholmes.txt +#-E enables extended regular expressions /c stands for change + + sed -En '/The[[:space:]]+[[:upper:]][[:alpha:]]{1,}/! s/[[:upper:]][[:alpha:]]{1,}[[:space:]]+[[:upper:]][[:alpha:]]{1,}/Noy/gp' sherlockholmes.txt + +#replace every name of a person or a place to Noy +#{1,} at least 1 ----- g for global -n only what has changed together with /p +#BTW it changes also "The *Word*" makes it more complex to achieve this part ChtGPT helped me with that + + + + + +sed -En 's/\((.{5,})\)/[\1]/gp' sherlockholmes.txt +#\( - not grouping +#p prints -n flag for printing only lines that changed +#\1 "capture" the first group. + +