Firstly you need to traverse the tree looking for files (not directories) with "find" and then get "cat" to display the contents. This example uses "cat -v" to guard against processing a file containing control characters.
Though we know nothing about your data this example uses "tr -s" to remove duplicate space and tab characters before translating space or tab into newline (similar to your code).
The most important bit is the "sort" which is imperative before running "uniq".
The "sort" command is the only command name which was not mentioned in your original post. I've tried to avoid introducing anything more exotic in case you have not yet covered a command on your course.
This may not fully match your requirement but should get you moving:
I've made a script using the code above. When I got the variables DIR and OUT declared in the code by the full path, everything works alright, but when I want declare them by the parameters the script doesn't work . Would be anybody so kind and show me how to write the script to be able to declare variables DIR and OUT from parameters?