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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
date format ali560045 Shell Programming and Scripting 4 01-25-2008 07:11 AM
date issue-find prevoius date in a patricular format bsandeep_80 UNIX for Advanced & Expert Users 3 11-15-2007 08:42 PM
Date format Knotty UNIX for Dummies Questions & Answers 2 04-11-2007 01:48 PM
convert mmddyy date format to ccyyddd format?? Bhups Shell Programming and Scripting 2 09-27-2006 11:30 PM
date format big123456 Shell Programming and Scripting 2 07-22-2005 04:57 AM

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-31-2007
biju.mp biju.mp is offline
Registered User
  
 

Join Date: Dec 2007
Location: Gurgaon/India
Posts: 2
Date Format

User entering Date in the below format.

Input date : 2007 12 31

Output expecting : Mon Dec 31

how can I convert in this format?

Thanks & Regards,
Biju MP
  #2 (permalink)  
Old 12-31-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,513
Code:
#!/bin/sh
s="2007 12 31"
year=`echo $s | cut -d" " -f1`
mon=`echo $s | cut -d" " -f2`
day=`echo $s | cut -d" " -f3`
cal $2 $1 | awk 'BEGIN{ 
                         d["Su"]="Sun"
                         d["Mo"]="Mon"
                         d["Tu"]="Tue"
                         d["We"]="Wed"
                         d["Th"]="Thu"
                         d["Fr"]="Fri"
                         d["Sa"]="Sat"
                         y[1]="Su"
                         y[2]="Mo"
                         y[3]="Tu"
                         y[4]="We"
                         y[5]="Th"
                         y[6]="Fr"
                         y[7]="Sa"
                         month["01"]="Jan"
                         month["02"]="Feb"
                         month["03"]="Mar"
                         month["04"]="Apr"
                         month["05"]="May"
                         month["06"]="Jun"
                         month["07"]="Jul"
                         month["08"]="Aug"
                         month["09"]="Sep"
                         month["10"]="Oct"
                         month["11"]="Nov"
                         month["12"]="Dec"
}

NR>2{
    for(i=1;i<=NF;i++){
        if ( $i == '"$day"' ){
            print d[y[i]],month['"$mon"'],$i
        }
    
    }
}'
output:
Code:
# ./test.sh
Mon Dec 31
  #3 (permalink)  
Old 12-31-2007
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,915
If the version of date on your OS supports the -d option and portability is not a major requirement, you could do something like

Code:
date -d "2007-12-31" "+%a %b %d"
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 06:30 PM.


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