unique words in files of folder and its subfolders

Hello, I tried to count all unique words of all files in one folder and its subfolders. Can anybody say me, why this doesnt work:

ls| find -d | cat | tr "\ " "\n"| uniq -u | wc -l

???
Cat writes only the names of those files, but not the wors, which should be in them.
Thanks for any advice.

Faculty of Mathematics and Physics, Charles University in Prague, The Czech Republic, Ondrej Tichy, ms.mff.cuni.cz/~ticho6am

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:

find . -type f -exec cat -v {} \;|tr -s ' ' | tr -s '\t' | tr ' ' '\n' | tr '\t' '\n'|sort|uniq|wc -l

Might well need refining to deal with blank lines etc. .

When testing, try building the pipeline command-by-command and looking at the output after each new addition to the pipeline.

Whether you use "uniq" or "uniq -u" or whatever is up to your understanding of the phrase "all unique words".

The solution:

ls| find -d |  xargs cat | tr "\ " "\n"| uniq -u | wc -l

:wink:

hi, i've the your solution and can't be the possible one.

why not? I think, it works...:confused:

@Dworza
It appears to contain syntax errors and logic errors.
Show me it working.

Uh..strange... I've tested that code again and it worked perfectly. The output of this code is just one number. I used bash shell.

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?

#!/bin/bash

DIR=/home/martin/java
OUT=/home/martin/abcd

A=`cd "$DIR" && ls| find -d | xargs cat | tr "\ " "\n"| uniq -u | wc -l`
B=`cd "$DIR" && ls| find -d | wc -l`
DIVISION=$(($A/$B))

if [ "$(ls $OUT | wc -l)" == '0' ]
then
echo $DIVISION>$OUT/pocet1
else
{
a=`ls $OUT | sort -n | tail -n1`
numToIncr=${a#${a%?}}
numToIncr=$(($numToIncr+1))
outDir=pocet$numToIncr
echo $DIVISION>$OUT/$outDir
}
fi

DIR="$1" and OUT="$2" perhaps?

The code showing error and basically strange one to compete.