From ed4c287f36a42825e58a26cdfeff158ce48a882c Mon Sep 17 00:00:00 2001 From: Arik9797 Date: Sat, 8 Feb 2025 14:36:20 +0000 Subject: [PATCH] hi all this is my answers i hope you will like them --- q1.sh | 17 ++++++++++++++++- q2.sh | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) mode change 100644 => 100755 q1.sh create mode 100755 q2.sh diff --git a/q1.sh b/q1.sh old mode 100644 new mode 100755 index f7ac848..01a4c1a --- a/q1.sh +++ b/q1.sh @@ -1 +1,16 @@ -This is q1 answer +#!/bin/bash + +--a = 3325 +awk 'END {print NR}' aliceinwonderland.txt + +--b = 395 +awk '{for (i=1; i<=NF; i++) if ($i ~ /Alice/) count++} END {print count}' aliceinwonderland.txt + +--c +awk '{for (i=1; i<=NF; i++) freq[$i]++} END {for (word in freq) if (freq[word] == 1) print word}' aliceinwonderland.txt + +--d +awk '{for (i=1; i<=NF; i++) freq[$i]++} END {for (word in freq) print freq[word], word}' aliceinwonderland.txt | sort -nr | head -5 + +--e = 4.37 +awk '{for (i=1; i<=NF; i++) {total += length($i); count++}} END {print total/count}' aliceinwonderland.txt diff --git a/q2.sh b/q2.sh new file mode 100755 index 0000000..569f227 --- /dev/null +++ b/q2.sh @@ -0,0 +1,15 @@ +#!/bin/bash +--a = 463 +sed -n '/Sherlock\|Holmes/p' sherlockholmes.txt | wc -l + +--b = 12797 +sed -n 's/Sherlock/&\n/g; s/Holmes/&\n/g; p' sherlockholmes.txt | wc -l + +--c +sed 's/^/Hello: /' sherlockholmes.txt + +--d +sed -E 's/\b[A-Z][a-z]+\s[A-Z][a-z]+/Arik Apl/g' sherlockholmes.txt + +--e +sed -E 's/\(([^()]*)\)/[\1]/g' sherlockholmes.txt