That code is an absolute mess. It's almost as if you're trying to make it difficult for us to help. The very, very least you can do is use sane indentation.
I didn't scrutinize it, but two things stand out in your most recent post. (1) You are not piping
sort|tail|head into the while-loop. (2) You don't use $i anywhere (perhaps that's intentional).
On a general note, you have not made any effort to provide useful feedback for the suggestions given. Have you confirmed that the directory exists and that there are files in it, per post #5? If you can't be bothered to help us account for the error messages that you report (when you report them), how do you expect us to help you fix the problems?
Quote:
Originally Posted by
Manu1234567
I have changed but my file contains different things.....Any other suggestions?
I suggest you be specific instead of vague.
Regards,
Alister