Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Friday January 02, 2009
04:48 AM

List of Directories Containing XML Docs

[ #38202 ]

As part of my holiday refactoring, I need to generate a list of directories containing XML docs. Surely there's something more natural than this?

find . -name '*.xml' | perl -nle '/(.*)\// && print $1' | uniq

I assumed there would be an option for find, but I didn't see it. (Well, gfind, that is. Solaris' find command is a pile o' junk, like so many other things on Solaris.)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • If you are using perl in that pipe, why not just use perl?

    perl -MFile::Find -e 'find(sub { return unless /[.]xml$/; print "$File::Find::dir\n"}, @ARGV)' .

    Best regards,

    life is short
  • Gnu Find has a -printf action which you can use to emit just the names of the directories, like this:

    find -name '*.xml' -printf '%h\n' | uniq

    I don't think it's possible to avoid the uniq though; -prune sounds promising, but isn't quite right to be useful here. So for a directory with lots of XML files in it, once it's found the first one and told you the directory you have to sit there and wait while it tells you again for all the others.