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

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.
  • (ls aggtests/pips/api/v1/xml/*.t; ls aggtests/pips/api/builder/*.t) | sort | uniq -d

    • "ls aggtests/pips/api/v1/xml/*.t"

      "ls... glob" FAIL. Please don't do that.

      • Randal L. Schwartz
      • Stonehenge
      • I just realized that message is probably insufficient. Here's the "dangerous use of ls" message, spelled out a bit better: []
        • Randal L. Schwartz
        • Stonehenge
        • OK, so had I thought a bit more I might have written

          echo .../*.t .../*.t | sort | uniq -d

          The other point, that filenames can contain special characters, I was aware of, but I tend to assume that 'my' files won't (unless I know that they do). If I were working on some arbitrary set of files I would have done the job in Perl (I was going to say find -print0 and {sort,uniq} -z would work, but apparently (my) uniq doesn't have a -z option. Weird.). Thanks for the correction, though, since it's important to be

          • echo .../*.t .../*.t | sort | uniq -d

            That won’t do what you wanted because echo will output the whole shebang on a single line. What you want instead is

            printf '%s\n' .../*.t .../*.t | sort | uniq -d

            But then that still won’t do what you wanted, because you aren’t chopping the base path off the file names, so no two lines will have the same content anyway. You need to something like this:

            printf '%s\n' .../*.t .../*.t | cut -d/ -f2- | sort | uniq -d

            Of course, as mentioned, that doesn’t account for the possibility of newlines in file names. And trying to do so is awkward since not all Unix utilities have switches to enable null- rather than newline-terminated records, uniq and cut among them.