diff --git a/q1.sh b/q1.sh index f7ac848..2128235 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,13 @@ -This is q1 answer +#!bin bash +#1 +awk 'END {print "Total lines: ",NR}' aliceinwonderland.txt +#2 +awk '{count += gsub(/ Alice /, "")} END {print "Occurrences of Alice:", count}' aliceinwonderland.txt +#3 +awk '{for (i=1; i<=NF; i++) freq[$i]++} END {for (word in freq) if (freq[word] == 1) print word}' aliceinwonderland.txt +#4 +awk '{for (i=1; i<=NF; i++) if (length($i) >= 2) freq[$i]++} END {for (word in freq) print word, freq[word]}' aliceinwonderland.txt | sort -k2 -nr | head -5 +#5 +awk '{for (i=1; i<=NF; i++) {total_length += length($i); total_words++}} END {print "Average word length:", total_length/total_words}' aliceinwonderland.txt + + diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..8fa333b --- /dev/null +++ b/q2.sh @@ -0,0 +1,12 @@ +#!bin bash +#1 +sed -n '/Sherlock\|Holmes/p' sherlockholmes.txt | wc -l +#2 +sed 's/Holmes\|Sherlock/&/g' sherlockholmes.txt | grep -o 'Holmes\|Sherlock' | wc -l +#3 +sed 's/^/Hello: /' sherlockholmes.txt +#4 +sed 's/\b[A-Z][a-z]\{1,\} [A-Z][a-z]\{1,\}\b/Chat GPT/g' filename.txt +#5 +sed 's/([^)]*)/\\[&\\]/g' sherlockholmes.txt +