Loading ...
Sorry, an error occurred while loading the content.

157Re: [NTS] Sorting Numbers and No-Sort: Remove Dups/Trips...

Expand Messages
  • Sheri
    Nov 9, 2002
    • 0 Attachment
      Hi Alan,

      I struggled and finally got the following working -- uses a pm module
      called Sort::Fields. Sample is first sorted as I think Jody was
      wanting it (chapter and verse treated as numeric), then the
      duplicates are removed. I think I've found a Perl way of removing
      duplicate lines from an unsorted input, but haven't tried to
      implement it.

      Sheri

      Sample Input:
      ChapterOne 13:15
      ChapterOne 13:3
      ChapterOne 14:3
      ChapterOne 15:11
      ChapterOne 15:13
      ChapterOne 15:18
      ChapterOne 15:5-6
      ChapterOne 15:6
      ChapterOne 15:8
      ChapterOne 16:23
      ChapterOne 16:27
      ChapterOne 16:4
      ChapterOne 17:28
      ChapterOne 18:7
      ChapterOne 120:2
      ChapterTwo 126:2
      ChapterOne 140:3
      ChapterOne 141:3
      ChapterOne 14:3
      ChapterTwo 126:2
      ChapterOne 15:5-6

      Sample Output:
      ChapterOne 13:3
      ChapterOne 13:15
      ChapterOne 14:3
      ChapterOne 15:5-6
      ChapterOne 15:6
      ChapterOne 15:8
      ChapterOne 15:11
      ChapterOne 15:13
      ChapterOne 15:18
      ChapterOne 16:4
      ChapterOne 16:23
      ChapterOne 16:27
      ChapterOne 17:28
      ChapterOne 18:7
      ChapterOne 120:2
      ChapterOne 140:3
      ChapterOne 141:3
      ChapterTwo 126:2

      H="_Perl Field Sorter and Dupe Remover"
      #all lines go in an array (memory intensive)
      @lines = <>; # Read entire file into an array
      use Sort::Fields;
      #first parameter is pattern for field delimiters
      @lines= fieldsort '[\s\:\-]', [1, '2n', '3n'], @lines;
      #next part extracts unique entries in a sorted array
      $prev = 'nonesuch';
      @lines = grep($_ ne $prev && (($prev) = $_), @lines);
      #finally, print array
      print @lines;

      H="Run Perl Sorter and Dupe Remover"
      ^!Jump Doc_Start
      ^!RunPerl Perl Field Sorter and Dupe Remover
    • Show all 26 messages in this topic