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.

Thanks,
Joe.
jkopokuAsked:
Who is Participating?
 
ahoffmannCommented:
date +"%m%d"|sed "s/^0//"

hope you know what 111 means then ;-)
0
 
biraCommented:
date +"%m%d"|sed "s/0//g"
0
 
TintinCommented:
bira.

Consider the date
30/10

using your sed regex, would yeild

3/1

Definitely not was is required.


jkopoku

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?

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

newdate=$day$mon
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
ozoCommented:
date +"%m %d" | awk '{print 0+$1"_"0+$2}
0
 
jkopokuAuthor Commented:
Tintin,
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.
0
 
TintinCommented:
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?
0
 
jkopokuAuthor Commented:
I will put in a request tomorrow. Thanks again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.