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
21 changes: 21 additions & 0 deletions q1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#q1

#a
awk '{print NR}' aliceinwonderland.txt | tail -1

#b
grep -o ' Alice ' aliceinwonderland.txt | awk '{a[$1]++} END {for (k in a) print a[k]}'
#another option only with awk
#awk '/ Alice /{count++} END {print count}' aliceinwonderland.txt

#c
awk '{for (i=1; i<=NF; i++) a[$i]++} END {for (word in a) if (a[word] == 1) print word}' aliceinwonderland.txt
#another option
#grep -o '[a-zA-Z]\+' aliceinwonderland.txt | sort | uniq -c | awk '$1 == 1 {print $2}'

#d
grep -o '[a-zA-Z]\+' aliceinwonderland.txt | awk '{a[$1]++} END {for (k in a) print a[k], k}' |sort -n | tail -5

#e
awk '{for (i=1; i<=NF; i++) {total_chars += length($i); total_words++}} END {print total_chars / total_words}' aliceinwonderland.txt

12 changes: 12 additions & 0 deletions q2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#q2
#a
sed -n '/Sherlock\|Holmes/p' sherlockholmes.txt | wc -l
#b
sed -n '/Sherlock\|Holmes/p' sherlockholmes.txt sherlockholmes.txt | grep -oE 'Sherlock|Holmes' | wc -l
#c
sed 's/^/hello /' sherlockholmes.txt
#d
sed -E 's/\b[A-Z][a-z]{1,}\s[A-Z][a-z]{1,}\b/yarin/g' sherlockholmes.txt
#e
sed -e 's/(/[/g' -e 's/)/]/g' sherlockholmes.txt