Re: Find duplicate numbers and replace
Re: Find duplicate numbers and replace
- Subject: Re: Find duplicate numbers and replace
- From: "Mark J. Reed" <email@hidden>
- Date: Wed, 14 May 2008 12:58:55 -0400
Hm. regex needs tightening up. as written,
3[F] hello
6003[F] there
would get replaced by
3[F] hello
6003a[F] there.
replace the
s/$n\\F\\]/
with
s/(^|\\D)$n\\F\\]/
to fix.
On Wed, May 14, 2008 at 12:50 PM, Mark J. Reed <email@hidden> wrote:
> On Wed, May 14, 2008 at 12:27 PM, Script2 <email@hidden> wrote:
>> I want to write a script that will find the second, third……occurrence of
>> number (the number is always before [F]) and add "a" to second occurrence,
>> "b" to third occurrence so on. Appreciate any suggestions or script
>> examples. OS 10.3
>
> This is a good candidate for Perl...
>
> do shell script ("perl -i.bak -e 'undef $/; $_ = <>; while
> (/(\\d+)\\[F\\]/g) { my $n = $1; my $a = \"a\"; substr($_, pos($_))
> =~ s/$n\\[F\\]/$n . $a++ .\"[F]\"/ge;} print;' " & POSIX path of
> myTextFile)
>
> As written it modifies the text file in place, after making a backup
> copy named by appending ".bak" to the original filename.
>
> --
> Mark J. Reed <email@hidden>
>
--
Mark J. Reed <email@hidden>
_______________________________________________
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