The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 01:07 PM
convert mmddyy date format to ccyyddd format?? Bhups Shell Programming and Scripting 2 09-27-2006 11:30 PM
changing the format of date nasirgondal Post Here to Contact Site Administrators and Moderators 1 06-08-2006 01:37 AM
Changing the format of date nhatch UNIX for Dummies Questions & Answers 4 04-11-2006 10:17 AM
Changing the date format Dream86 Shell Programming and Scripting 10 06-08-2005 01:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-07-2005
Sabari Nath S Sabari Nath S is offline
Registered User
  
 

Join Date: Jul 2005
Location: Chennai
Posts: 46
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
  #2 (permalink)  
Old 12-07-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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
  #3 (permalink)  
Old 12-07-2005
Sabari Nath S Sabari Nath S is offline
Registered User
  
 

Join Date: Jul 2005
Location: Chennai
Posts: 46
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]
  #4 (permalink)  
Old 12-07-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

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

See this post

You need to modify that to remove the HHMMSS
  #5 (permalink)  
Old 12-07-2005
Sabari Nath S Sabari Nath S is offline
Registered User
  
 

Join Date: Jul 2005
Location: Chennai
Posts: 46
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 .....
  #6 (permalink)  
Old 12-07-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0