[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Date format

Posted on 2006-03-29
8
Medium Priority
?
659 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:jkopoku
7 Comments
 
LVL 6

Expert Comment

by:bira
ID: 16326887
date +"%m%d"|sed "s/0//g"
0
 
LVL 48

Expert Comment

by:Tintin
ID: 16328477
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
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 16329819
date +"%m%d"|sed "s/^0//"

hope you know what 111 means then ;-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 85

Expert Comment

by:ozo
ID: 16329914
date +"%m %d" | awk '{print 0+$1"_"0+$2}
0
 

Author Comment

by:jkopoku
ID: 16336034
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
 
LVL 48

Expert Comment

by:Tintin
ID: 16337902
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
 

Author Comment

by:jkopoku
ID: 16338306
I will put in a request tomorrow. Thanks again.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month19 days, 4 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question