Date: Sat, 30 Aug 2008 20:40:24 -0700 From: perryh@pluto.rain.com To: rambiusparkisanius@gmail.com, freebsd-questions@freebsd.org Subject: Re: Formatting dates to a specific pattern Message-ID: <48ba12a8.13Xw0Q1qzIqVH3mb%perryh@pluto.rain.com> In-Reply-To: <EE2163B05BDE434C6CD85CE0@Macintosh.local> References: <89ce7f740808301652g169fa4d2v3fe5eff06100e31e@mail.gmail.com> <EE2163B05BDE434C6CD85CE0@Macintosh.local>
next in thread | previous in thread | raw e-mail | index | archive | help
> > 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?48ba12a8.13Xw0Q1qzIqVH3mb%perryh>