diff --git a/q1.sh b/q1.sh index f7ac848..7ad089a 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,12 @@ This is q1 answer + +#a +awk 'END {print NR}' aliceinwonderland.txt +#b +awk '{for (i=1; i<=NF; i++) if ($i=="Alice") count++} END {print count}' aliceinwonderland.txt +#c + awk '{for (i=1; i<=NF; i++) a[$i]++} END {for (k in a) if(a[k]==1) print k}' aliceinwonderland.txt +#d +awk '{for (i=2; i<=NF-1; i++) a[$i]++} END {for (k in a) print a[k],k}' aliceinwonderland.txt | sort -n | tail -5 +#e +awk '{for (i=1; i<=NF; i++) {sum=sum+length($i); count++}} END {print sum/count}' aliceinwonderland.txt y diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..1c04420 --- /dev/null +++ b/q2.sh @@ -0,0 +1,11 @@ +#a +sed -E -n '/(Sherlock|Holmes)/p' sherlockholmes.txt | wc -l +#b +sed -E 's/\b(Sherlock|Holmes)\b/\n\1\n/g' sherlockholmes.txt | grep -E 'Sherlock|Holmes' | wc -l +#c +sed -E 's/^/Hello:/' sherlockholmes.txt +#d +sed -E 's/[[:upper:]]{1}[a-z]+\s[[:upper:]]{1}[a-z]+/Amit/g' sherlockholmes.txt +#e +sed -E 's/\((.*)\)/[\1]/g' sherlockholmes.txt +