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
15 changes: 14 additions & 1 deletion q1.sh
Original file line number Diff line number Diff line change
@@ -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}'



27 changes: 27 additions & 0 deletions q2.sh
Original file line number Diff line number Diff line change
@@ -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.