Date format

Hey Experts,
I have a script that gives me yesterday's date, but I want the date to be in d/m format as oppose to dd/mm format. For example, 0309 should be 39. Can any body help. I have to ftp some file daily from a rmote site, and the file name convernation is like joe3_1.xml.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

date +"%m%d"|sed "s/0//g"

Consider the date

using your sed regex, would yeild


Definitely not was is required.


How can you possibly squeeze the date 22/12 into dm format?  Did you mean you want the output of dm to have leading zeros stripped?

day=`echo $date|cut -c1-2|sed "s/^0//"`
mon=`echo $date|cut -c3-4|sed "s/^0//"`

date +"%m%d"|sed "s/^0//"

hope you know what 111 means then ;-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

date +"%m %d" | awk '{print 0+$1"_"0+$2}
jkopokuAuthor Commented:
It was your answer I intented to accept, and I accidentally clikck on ozo answer. Although, his work, but yours worked better. I don't know how to undo the accepted answer. Thanks a lot.
You can put a request in if you really want.  I'm not too fussed.

Mind you, I would be curious how you interpret dates like ahoffman mentioned.

Is '111' the 11 Jan or 1 Nov?
jkopokuAuthor Commented:
I will put in a request tomorrow. Thanks again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.