From owner-freebsd-questions@FreeBSD.ORG Sun Aug 31 03:48:37 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 AB329106566B for ; Sun, 31 Aug 2008 03:48:37 +0000 (UTC) (envelope-from perryh@pluto.rain.com) Received: from agora.rdrop.com (agora.rdrop.com [199.26.172.34]) by mx1.freebsd.org (Postfix) with ESMTP id 72CEB8FC16 for ; Sun, 31 Aug 2008 03:48:37 +0000 (UTC) (envelope-from perryh@pluto.rain.com) Received: from agora.rdrop.com (66@localhost [127.0.0.1]) by agora.rdrop.com (8.13.1/8.12.7) with ESMTP id m7V3mXYj015550 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 30 Aug 2008 20:48:33 -0700 (PDT) (envelope-from perryh@pluto.rain.com) Received: (from uucp@localhost) by agora.rdrop.com (8.13.1/8.12.9/Submit) with UUCP id m7V3mXc9015549; Sat, 30 Aug 2008 20:48:33 -0700 (PDT) Received: from fbsd61 by pluto.rain.com (4.1/SMI-4.1-pluto-M2060407) id AA14921; Sat, 30 Aug 08 20:37:59 PDT Date: Sat, 30 Aug 2008 20:40:24 -0700 From: perryh@pluto.rain.com To: rambiusparkisanius@gmail.com, freebsd-questions@freebsd.org Message-Id: <48ba12a8.13Xw0Q1qzIqVH3mb%perryh@pluto.rain.com> References: <89ce7f740808301652g169fa4d2v3fe5eff06100e31e@mail.gmail.com> In-Reply-To: User-Agent: nail 11.25 7/29/05 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: 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 03:48:37 -0000 > > I need to format the current date ... to the pattern > > m-d-yyyy ... date(1) seems to always put leading zeros. > > # date "+%m-%d-%Y" | sed 's/^0//g' > 8-30-2008 Not quite. That fixes the month, but not the day: $ echo 02-04-2008 | sed 's/^0//g' 2-04-2008 (The g does nothing, because the ^ can match only at the beginning of a line.) This does both: $ echo 02-04-2008 | sed -e 's/^0//' -e 's/-0*/-/' 2-4-2008