From 47a81b501f140b7cc66c23d9df927e268e94d7fb Mon Sep 17 00:00:00 2001 From: sahar turgeman Date: Sun, 9 Feb 2025 16:55:46 +0200 Subject: [PATCH 1/2] add q1.sh --- q1.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 + From 4fe61a404156fd0f46bfcd1fb2548e6a7d65175a Mon Sep 17 00:00:00 2001 From: sahar turgeman Date: Sun, 9 Feb 2025 16:57:52 +0200 Subject: [PATCH 2/2] add q2.sh --- q2.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 q2.sh 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