Use wc command to get the number of lines (if I remember correctly, wc adds one or subtracts one from the actual count). Add the total number, divided by number of files for the average number of lines.
And i hope last thing that i will ask you...If i don't input nothining in terminal for a directory, how can i make that this program will search current directory? I will post my code...
echo "Directory: "
read directory
typeset -i cnt=0
typeset -i sum=0
if [ $directory != "" ]; then
for file in "${directory}"/*
do
# [ -f "${file}" ] && echo "file->[${file} lines->[$(wc -l < ${file})]"
cnt=$(( cnt + 1 ))
sum=$(( sum + $(wc -l < ${file})))
done
echo ${sum} "/" ${cnt} "=" "$(echo "scale=2; $sum / $cnt " | bc)"
else
for file in "${directory}"/* #here i will like to heave current directory
do
# [ -f "${file}" ] && echo "file->[${file} lines->[$(wc -l < ${file})]"
cnt=$(( cnt + 1 ))
sum=$(( sum + $(wc -l < ${file})))
done
echo ${sum} "/" ${cnt} "=" "$(echo "scale=2; $sum / $cnt " | bc)"
fi
Hi .. it was really informative.. Thanks for that ..
I have a similar situation here , I just need to get the counts (Number of files) in a directory ..
I can Place the directory names in some files .. the shell script should read the file and login to those directories and Print the values for each directories !!