diff --git a/q1.sh b/q1.sh index f7ac848..385718f 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,48 @@ +<<<<<<< HEAD This is q1 answer +======= +#a +echo "a.the number of rows are:" +cat aliceinwonderland.txt | awk 'END{print NR}' + +#b +echo "b.the number of Alice shown:" +cat aliceinwonderland.txt | awk '/ Alice / {count++} END{print count}' + +#c +cat aliceinwonderland.txt | +awk ' +{ + for ( i=1 ; i <= NF; i++ ) + count [$i]++ +} +END { + for (c in count) + if (count[c] == 1) + print c +} ' + +#d +cat aliceinwonderland.txt | awk ' +{ + for (i=1 ; i<=NF ; i++) + count[$i]++ +} +END { + for (c in count) + print count[c],c +}' | sort -nr | head -5 + +#e +cat aliceinwonderland.txt | +awk '{ + for (i = 1; i <= NF; i++) + { + counterlen += length($i) + countersum++ + } +} +END { + print counterlen / countersum +}' +>>>>>>> dbc7ccf (q1 and q2 anwser) diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..6bdbed9 --- /dev/null +++ b/q2.sh @@ -0,0 +1,15 @@ +#a +cat sherlockholmes.txt | sed -n '/Sherlock\|Holmes/p' | wc -l + +#b +cat sherlockholmes.txt | sed 's/[[:space:]]/\n/g' | sed -n -E '/(Sherlock|Holmes)/p' | wc -l + +#c +cat sherlockholmes.txt | sed -n 's/^.\{70,\}$/"Long line"/' + +#d +cat sherlockholmes.txt | sed -E 's/[[:upper:]][[:lower:]]{1,}[[:space:]]+[[:upper:]][[:lower:]]{1,}/Adi Hirsch/g' + +#e +cat sherlockholmes.txt | sed -E 's/\(([^()]*)\)/[\1]/g' +