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


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