Count distinct word in file coderinme

Count distinct word in file coderinme

A file called wordfile consists of several words. Write a shell script which will receive a list of filenames, the
first of which would be wordfile. The shell script should report all occurrences of each word in wordfile in the
rest of the files supplied as arguments.

if [ $# -lt 2 ]; then
echo "Usage: $0 wordlist file1 [file2 ...]"
exit 1
#initialising array elements to 0
declare -A arr
for i in `cat $1`; do
for i in `cat $1`
for j in "$@"; do
if [[ $1 == $j ]]; then
for k in `cat $j`; do
if [[ $i == $k ]]; then
arr["$i"]=`expr ${arr["$i"]} + 1`
for i in `cat $1`; do
echo -n "Number of occurences of "
tput bold
echo -n "'$i'"
tput sgr0
echo " are: "${arr["$i"]}; done

For more programs in shell, visit our Shell Coder Archives
count distinct word

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without prior written permission of website admin, except in case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

A web developer(Front end and Back end), and DBA at Currently working as Salesforce Developer @ Tech Matrix IT Consulting Private Limited. Check me

Leave a reply:

Your email address will not be published.