#!/bin/sh
if [ $# != 1 ]; then
	echo "usage: "`basename $0`" dir"
	exit 1
fi
if [ -d $1 ]; then
	for a in `ls $1`
	do
		echo -n $a" " >> $1.txt
		sed 's/\./ /g' $1/$a | awk '{print NF}' >> $1.txt
	done
	sort -n -k 2,3 $1.txt | sed 's/\.txt//g'
	rm $1.txt
else
	echo $1" does not exist."
fi
