From owner-freebsd-questions@FreeBSD.ORG Sun Aug 31 01:47:12 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9D691106564A for ; Sun, 31 Aug 2008 01:47:12 +0000 (UTC) (envelope-from prad@towardsfreedom.com) Received: from idcmail-mo1so.shaw.ca (idcmail-mo1so.shaw.ca [24.71.223.10]) by mx1.freebsd.org (Postfix) with ESMTP id 6DB948FC15 for ; Sun, 31 Aug 2008 01:47:12 +0000 (UTC) (envelope-from prad@towardsfreedom.com) Received: from pd4ml1so-ssvc.prod.shaw.ca ([10.0.141.141]) by pd3mo1so-svcs.prod.shaw.ca with ESMTP; 30 Aug 2008 19:47:11 -0600 X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.0 c=0 a=KoDPwd6_AAAA:8 a=nsX4qRhHqBKdzmV5a0AA:9 a=K2QKrHD7VAPNR7Bxr90A:7 a=hiP8WqOl5kSTLjGNUinkAc9OmpoA:4 a=MSl-tDqOz04A:10 a=b3B20UsTnpUA:10 Received: from unknown (HELO gom.home) ([70.67.160.177]) by pd4ml1so-dmz.prod.shaw.ca with ESMTP; 30 Aug 2008 19:47:11 -0600 Received: from gom.home (localhost [127.0.0.1]) by gom.home (Postfix) with ESMTP id DD47117037 for ; Sat, 30 Aug 2008 18:47:10 -0700 (PDT) Date: Sat, 30 Aug 2008 18:47:10 -0700 From: prad To: freebsd-questions@freebsd.org Message-ID: <20080830184710.2a618fad@gom.home> In-Reply-To: <89ce7f740808301652g169fa4d2v3fe5eff06100e31e@mail.gmail.com> References: <89ce7f740808301652g169fa4d2v3fe5eff06100e31e@mail.gmail.com> X-Mailer: Claws Mail 3.3.1 (GTK+ 2.12.1; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: Formatting dates to a specific pattern X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 Aug 2008 01:47:12 -0000 On Sun, 31 Aug 2008 02:52:07 +0300 "Ivan \"Rambius\" Ivanov" wrote: > I need to format the current date (as returned by date(1) ) to the > pattern m-d-yyyy, where m is the month in one or digits, d is the day > in one or two digits, and yyyy is the year in four digits. The problem > for me is the day and the month, for example August should be 8, and > not 08, and 5th of September should be 9-5-2008 and not 09-05-2008. > hello rambius! you can give this script a try - it seems to do what you want and has comments too. save it as de0.sh, chmod +x it and run it as ./de0.sh `date "+%m-%d-%Y"` (there are no doubt better ways to do what you want especially if you use a more advanced shell like zsh, but this may be sufficient) ================== #!/bin/sh # removes 0 from mm-dd-yyyy # run with ./de0.sh `date "+%m-%d-%Y"` #the whole date from argument $1 mmddyyyy=$1 #get the year yyyy=${mmddyyyy##*-} #get the month and day mmdd=${mmddyyyy%-*} #get the day dd=${mmdd#*-} #get the month mm=${mmdd%-*} #remove 0 if only at beginning of month, day and add on the year echo ${mm#0}-${dd#0}-$yyyy ================== -- In friendship, prad ... with you on your journey Towards Freedom http://www.towardsfreedom.com (website) Information, Inspiration, Imagination - truly a site for soaring I's