![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| convert date format YYYYMMDD to MM/DD/YYYY | nasirgondal | Shell Programming and Scripting | 8 | 04-08-2009 11:56 AM |
| how to convert the string YYYYMMDD into YYYY.MM.DD | spatra | UNIX for Dummies Questions & Answers | 1 | 07-23-2008 08:18 AM |
| Convert filenames with DDMMYYYY to YYYYMMDD | cbo0485 | Shell Programming and Scripting | 10 | 04-24-2008 01:48 PM |
| get yesterday in yyyymmdd format | aaron_fong | Shell Programming and Scripting | 13 | 03-14-2008 03:14 PM |
| Converting YYYYMMDD to Julian | dfran1972 | Shell Programming and Scripting | 5 | 04-28-2005 11:34 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
An example how to convert the date format DD-MMM-YY to YYYYMMDD assuming the century is 2000 if the year is in 2 digits: Code:
awk -v var="01-JUL-00" '
BEGIN{
split("JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC", month, " ")
for (i=1; i<=12; i++) mdigit[month[i]]=i
m=toupper(substr(var,4,3))
dat="20"substr(var,8,20)substr(var,1,2) sprintf("%02d",mdigit[m])
print dat
}'
Regards |
|
||||
|
awk -v does nt seem to work.
awk -v var="01-JUL-00" ' BEGIN{ split("JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC", month, " ") for (i=1; i<=12; i++) mdigit[month[i]]=i m=toupper(substr(var,4,3)) dat="20"substr(var,8,20)substr(var,1,2) sprintf("%02d",mdigit[m]) print dat }' awk: syntax error near line 1 awk: bailing out near line 1 So i tried this echo $var | awk 'BEGIN{FS="-";OFS="";split("JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC", month, " ") for (i=1; i<=12; i++) mdigit[month[i]]=i m=toupper(substr(var,4,3)) dat="20"substr(var,8,20)substr(var,1,2) sprintf("%02d",mdigit[m]) print dat}' and the output is 2000 and not 20070701 ![]() Any suggestions?? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|