diff --git a/q1.sh b/q1.sh index f7ac848..2e4a708 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,24 @@ -This is q1 answer +#!/bin/bash + + +#a + +awk 'END {print NR}' aliceinwonderland.txt + +#b + +awk '{ for (i=1; i<=NF; i++) if ($i=="Alice") c++} END { print c }' aliceinwonderland.txt + +#C + +awk '{ for (i=1; i <= NF; i++) print $i }' aliceinwonderland.txt | sort | uniq -c | sort | awk '$1==1 { print $2 }' + +#d + +awk '{ for (i=1; i <= NF; i++) print $i }' aliceinwonderland.txt | sort | uniq -c | sort -n | tail -n 5 + +#e + +a=$(awk '{ for (i=1; i<=NF; i++) sum += length($i) } END { print sum }' aliceinwonderland.txt ) +b=$(awk '{ for (i=1; i<=NF; i++) total++ } END { print total }' aliceinwonderland.txt) +echo $a/$b | bc -l diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..123ebef --- /dev/null +++ b/q2.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +#a + +sed -n '/\\|\/p' sherlockholmes.txt | wc -l + +#b + +tr -d '[:punct:]' < sherlockholmes.txt | tr -s [:space:] '\n' | sed -n -E '/^(Sherlock|Holmes)$/p' | wc -l + +#c + +sed -E 's/^.{70,}$/Long line/' sherlockholmes.txt + +#d + +sed -E 's/\<[A-Z][a-z]{1,} [A-Z][a-z]{1,}\>/Gali Davidov/g' sherlockholmes.txt + +#e + +sed 's/)/]/g' sherlockholmes.txt | sed 's/(/[/g' +