• 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: Adding a leading zero
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding a leading zero


  • Subject: Re: Adding a leading zero
  • From: "Steven D. Majewski" <email@hidden>
  • Date: Wed, 4 Apr 2007 17:35:35 -0400


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. )

-- Steve Majewski



I am using this line to extract the modification date of a file
ls -lT /Users/gunno/Library/Preferences/Flexklockan.plist | awk '{print $6 $7 $9}'
The result is Apr42007
How can I add a leading zero to the day digit?
Or is there another and better way to get the modiicaion date?
(Don't want to use /Developer/Tools/GetFileInfo)

_______________________________________________ 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: Adding a leading zero
      • From: "Steven D. Majewski" <email@hidden>
References: 
 >Re: Adding a leading zero (From: <email@hidden>)

  • Prev by Date: Re: Adding a leading zero
  • Next by Date: Re: Adding a leading zero
  • Previous by thread: Re: Adding a leading zero
  • Next by thread: Re: Adding a leading zero
  • Index(es):
    • Date
    • Thread