With the output of a ‘find’ command, or other, sorted list of entries:
(o=; while read f; do [ -n "$o" ] && [ "${f#$o/}" == "$f" ] && echo "$o"; o="$f"; done; echo "$o") < list
Meaning: show a line only if next line doesn’t include this one (if last line is a directory, it still shows).


Comments