• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Find duplicate numbers and replace
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Find duplicate numbers and replace


  • Subject: Re: Find duplicate numbers and replace
  • From: Skeeve <email@hidden>
  • Date: Wed, 14 May 2008 20:41:05 +0200

How long do you use perl, Mark? It's a bit inefficient what you wrote.

#!/usr/bin/perl -i.bak
use strict;
use warnings;

my %numbers; # here our numbers get "counted"

while (<>) {
   # append the count if needed
   # not: It was not defined what should happen after "z"
   # here "aa" will follow
   if (s/^(\d+)(?=\[F\])/$1.($numbers{$1}++||'')/e) {
      # Was it the first occurence?
       if ($numbers{$1} eq 1) {
           # then fix the 1 to become an "a"
           $numbers{$1}= 'a';
       }
   }
   print;
}

It should work like yours but does not slurp in the whole file (which could fail if we are working cross platform) and doesn't us as many regexes as yours does.

as a do shell script:

do shell script "perl -i.bak -e " & (quoted form of "use strict;
use warnings;

my %numbers; # here our numbers get "counted"

while (<>) {
   # append the count if needed
   # not: It was not defined what should happen after "z"
   # here "aa" will follow
   if (s/^(\d+)(?=\[F\])/$1.($numbers{$1}++||'')/e) {
      # Was it the first occurence?
       if ($numbers{$1} eq 1) {
           # then fix the 1 to become an "a"
           $numbers{$1}= 'a';
       }
   }
   print;
}") & " " & (quoted form of POSIX PATH of inputfile)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: Find duplicate numbers and replace
      • From: "Mark J. Reed" <email@hidden>
References: 
 >Re: Re1: Mail scripting : How to select… continuation... (From: Philip Aker <email@hidden>)
 >Find duplicate numbers and replace (From: "Script2" <email@hidden>)
 >Re: Find duplicate numbers and replace (From: "Mark J. Reed" <email@hidden>)
 >Re: Find duplicate numbers and replace (From: "Mark J. Reed" <email@hidden>)
 >Re: Find duplicate numbers and replace (From: "Mark J. Reed" <email@hidden>)
 >Re: Find duplicate numbers and replace (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: Yet another Newbie
  • Next by Date: Re: AppleScript Studio & File Paths
  • Previous by thread: Re: Find duplicate numbers and replace
  • Next by thread: Re: Find duplicate numbers and replace
  • Index(es):
    • Date
    • Thread