سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top