Question

find ./2012 -type f | cut -d '/' -f 5 | uniq

The usual filenames look like

./2012/NY/F/Zoe
./2012/NJ/M/Zoe

I suppose the command above should give non-duplicated result of file names like Zoe only for once, but it turns out not so.

Why? and how should I write to get the desired result?

Était-ce utile?

La solution

uniq only detects duplicates if they're in consecutive lines. The usual idiom is to sort | uniq to ensure that any duplicates will appear together.

Autres conseils

uniq requires the duplicates to be adjacent, which means you need to sort the input, which means you might as well use sort -u;

find 2012 -type f | cut -d/ -f5 | sort -u
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top