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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Date Conversion jgrant746 Shell Programming and Scripting 3 05-24-2008 02:16 PM
Date Conversion MJDRM UNIX for Dummies Questions & Answers 5 01-29-2008 06:20 PM
date conversion tonet Shell Programming and Scripting 2 07-07-2006 10:23 AM
Date Conversion dafidak UNIX for Advanced & Expert Users 2 07-04-2006 05:16 PM
date conversion sunil bajaj UNIX for Dummies Questions & Answers 3 04-17-2002 01:54 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 Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 05-18-2006
mab_arif16 mab_arif16 is offline
Registered User
  
 

Join Date: May 2006
Posts: 14
Date conversion

Hi
I want to convert MAY 05 2005 01:15:00PM date format to 2005/05/05 01:15:00PM .
CAn somebody suggest me a code ,I am new to unix shell programming.
Thanks
Arif
  #2 (permalink)  
Old 05-18-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
one way.......

echo 'MAY 05 2005 01:15:00PM' | awk -f mab.awk

mab.awk:

Code:
BEGIN {
  monN=split("JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC", months)
  for(i=1; i<=monN; i++) {
    months[months[i]]=i;
    delete months[i];
  }
}

{ printf("%s/%02d/%s %s\n",  $3, months[toupper($1)], $2, $3) }

  #3 (permalink)  
Old 05-18-2006
mab_arif16 mab_arif16 is offline
Registered User
  
 

Join Date: May 2006
Posts: 14
Thanks
That was perfect .
Arif
  #4 (permalink)  
Old 05-19-2006
Raom Raom is offline
Registered User
  
 

Join Date: Sep 2005
Location: india
Posts: 79
date +%Y/%m/%d,%H:%M:%S |sed 's/,/ /g'
  #5 (permalink)  
Old 05-19-2006
mab_arif16 mab_arif16 is offline
Registered User
  
 

Join Date: May 2006
Posts: 14
HI
Can we convert the date to a 24 hour format .
MAY 05 2005 01:15:00PM date format to 2005/05/05 13:15:00
Thanks Arif
  #6 (permalink)  
Old 05-19-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
BEGIN {
  monN=split("JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC", months)
  for(i=1; i<=monN; i++) {
    months[months[i]]=i;
    delete months[i];
  }
}

function conv2mil(time,   tA, tAnum, pm_am) {
  tAnum=split(time, tA, ":")
  sec=substr(tA[tAnum], 1, length(tA[tAnum])-2)
  pm_am=toupper(substr(tA[tAnum], length(tA[tAnum])-1))
  hour= (pm_am ~ /^P./) ? tA[1] + 12 : tA[1]
  return (hour ":" tA[2] ":" sec)
}

{ printf("%s/%02d/%s %s\n",  $3, months[toupper($1)], $2, conv2mil($4) ) }

  #7 (permalink)  
Old 05-06-2009
aller_in aller_in is offline
Registered User
  
 

Join Date: May 2009
Posts: 2
Smile

Quote:
Originally Posted by vgersh99 View Post
one way.......

echo 'MAY 05 2005 01:15:00PM' | awk -f mab.awk

mab.awk:

Code:
BEGIN {
  monN=split("JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC", months)
  for(i=1; i<=monN; i++) {
    months[months[i]]=i;
    delete months[i];
  }
}
 
{ printf("%s/%02d/%s %s\n",  $3, months[toupper($1)], $2, $3) }


Hi vgersh99 - hope you're still here i saw this thread and it really helped me a lot! however i'm having difficulty now figuring out how to convert this date format (May 5 13:01) to yyyymmddhhmm appending the current year (2009).

for sample: (May 5 13:01) will be transformed to 200905051301

the reason i want to have it this way is in order for me to take the time difference of two variables.

I've tried modifying your script by using sprintf, but i failed to make it work

Hope you can help me with this

Many thanks!
Closed Thread

Bookmarks

Tags
linux, ubuntu

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 12:47 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