The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
changing the format of date in unix trichyselva UNIX for Dummies Questions & Answers 5 03-20-2008 09:07 AM
convert mmddyy date format to ccyyddd format?? Bhups Shell Programming and Scripting 2 09-27-2006 08:30 PM
changing the format of date nasirgondal Post Here to Contact Site Administrators and Moderators 1 06-07-2006 10:37 PM
Changing the format of date nhatch UNIX for Dummies Questions & Answers 4 04-11-2006 07:17 AM
Changing the date format Dream86 Shell Programming and Scripting 10 06-08-2005 10:35 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-06-2005
Registered User
 

Join Date: Jul 2005
Location: Chennai
Posts: 39
Changing date format

Hi,

Is there any way to change one date format to another ?? I mean I have a file having dates in the format (Thu Sep 29 2005) ... and i wud like to change these to YYYYMMDD format .. is there any command which does so ?? Or anything like enum which we have in C ??

Thanks in advance,

Sabari Nath S
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-06-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
You did not mention which OS

The following works well for GNU date.

Code:
sh-2.05b$ cat sabri.ksh 
#! /bin/ksh
epoch=$(date -d "Thu Sep 29 2005" +%Y%m%d)
echo $epoch
sh-2.05b$ ./sabri.ksh 
20050929
Reply With Quote
  #3 (permalink)  
Old 12-06-2005
Registered User
 

Join Date: Jul 2005
Location: Chennai
Posts: 39
Hi Vino ...

this is the version of the OS I am using ..

$ version
Machine hardware: sun4u
OS version: 5.9
Processor type: sparc
Hardware: SUNW,Sun-Fire

And its not accepting -d option for date command ...

$ date -d "Thu Sep 29 2005" +%Y%m%d
date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
Reply With Quote
  #4 (permalink)  
Old 12-06-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
I had written a small script to change such dates into YYYYMMDDHHMMSS

See this post

You need to modify that to remove the HHMMSS
Reply With Quote
  #5 (permalink)  
Old 12-06-2005
Registered User
 

Join Date: Jul 2005
Location: Chennai
Posts: 39
Thanks Vino ... i modified that and it works fine for me .....
Now I am getting a list of dates as result from some long command and i am piping that to xargs -l1 sabri.ksh ; and getting the conversion done ... thx a lot ...

but still let me ask just out of curiosity tht do we have any thing like enum in unix or awk so that i can avoid using a ksh script and do that in command line itself .....
Reply With Quote
  #6 (permalink)  
Old 12-06-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
Quote:
Originally Posted by Sabari Nath S
but still let me ask just out of curiosity tht do we have any thing like enum in unix or awk so that i can avoid using a ksh script and do that in command line itself .....
Something like a one-liner ? I doubt it.

Even if it in awk, it would go into few lines.

As for enum in shell scripting, I dont know it is available. If at all, it is present, then awk could have it, since it has a syntax which resembles C syntax.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0