Re: Adding a leading zero
Re: Adding a leading zero
- Subject: Re: Adding a leading zero
- From: "Steven D. Majewski" <email@hidden>
- Date: Wed, 4 Apr 2007 17:51:47 -0400
On Apr 4, 2007, at 5:35 PM, Steven D. Majewski wrote:
On Apr 4, 2007, at 4:36 PM, <email@hidden>
<email@hidden> wrote:
Michelle,
thanks for your answer. What I had in mind was piping it thru sed
or something like that. The leading zero is only needed for dates
0-9. The month will always be three chacters and the year four
digits, it is only the day that will vary
I have been playing with InDesign JavaScript and come up with a
two step solution.
myString='Apr42007'
myString=myString.replace(/(\D+)(\d+)/, '$10$2');
myString=myString.replace(/(\D{3})(\d{6}$)/, '$1$2');
I am sure this can be done much more simple and elegant, but I
don't know how to transfer it to a tool like sed.
Well: This IS the AppleScript Users list -- you shouldn't be
surprised that you
got an Applescript answer!
But if you do want to do it in the shell, there's no need to pipe
it to sed when
you're already using awk, which is a pretty complete text
processing language.
Try replacing your awk command with:
awk '{ if (length($7)==1) { $7 = "0" $7 ; } print $6 $7 $9 }'
( You could stick "-" in between the $n params to make the names
more readable. )
In fact, an even better way in awk is to use a format string with
sprintf:
awk '{ print sprintf("%3s-d-M",$6,$7,$9) }'
outputs something like:
Mar-03-2007
Jan-10-2007
Mar-30-2007
Jan-11-2007
Mar-08-2007
Mar-23-2007
Mar-23-2007
Mar-29-2007
Mar-29-2007
Mar-30-2007
Mar-29-2007
Mar-27-2007
Jan-09-2007
( The decimal format specifier works because awk does automagic
coercions
between strings and numbers. )
_______________________________________________
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