gawk convert 2012-Jun-13 to 2012-06-13


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting gawk convert 2012-Jun-13 to 2012-06-13
# 1  
Old 06-13-2012
gawk convert 2012-Jun-13 to 2012-06-13

I have a value in a file i am processing that has a date like "2012-Jun-13"

how can I convert a date like that 2012-06-13?

Am I stuck building an array of three digit months and corresponding numbers and running through the logic of figuring out the number??

or can I convert this with strftime? if so I cant figure out how... Im also cool with dropping down to the shell level and using gnu date to do this. But I dont know how to pull a system call back into gawk as a variable.

Any ideas?

---------- Post updated at 10:26 AM ---------- Previous update was at 10:17 AM ----------

I found another post details what I need to do this with a system call..

Quote:
Originally Posted by fbg

I could find the answer in other post. Need to do:

echo 40 | awk ' { comm="test.sh "$1; comm | getline y; close(comm); print y } '

Is a nice trick
If anyone knows how to do this without a system call, i would still like to know.

Thanks,
Trey
# 2  
Old 06-13-2012
Code:
echo "2012-Jun-13" | awk -F- 'BEGIN {
	a["Jan"] = "01";
	a["Feb"] = "02";
	a["Mar"] = "03";
	a["Apr"] = "04";
	a["May"] = "05";
	a["Jun"] = "06";
	a["Jul"] = "07";
	a["Aug"] = "08";
	a["Sep"] = "09";
	a["Oct"] = "10";
	a["Nov"] = "11";
	a["Dec"] = "12";
} { print $1 FS a[$2] FS $3 }'

Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. HP-UX

HP ux 11i v3 september 2012 Media

Hello Friends, I bought HP-UX 9000 series server. They shipped it with HP-UX 11.31 March 2014 version operating system. But i want to reload it with HP ux 11i v3 september 2012. I have only hardware support for this box, so i cant get it from HP site. Can any tell me where can i download it.... (4 Replies)
Discussion started by: corequad
4 Replies

2. What is on Your Mind?

Place your bits - 2012 FIFA Ballon d'Or and 2012 FIFA World Coach of the Year

I have added two new sports events. The FIFA Ballon d'Or is an association football award given annually to the player who is considered to have performed the best in the previous season. It is awarded based on votes by coaches and captains of international teams, as well as journalists from... (0 Replies)
Discussion started by: ni2
0 Replies

3. Shell Programming and Scripting

Date conversion help from dd/mm/yyyy to dd/Mon/yyyy i.e. 28/10/2012 to 28/Oct/2012

Hi I have a problem with Date format in my code. 1st I am trying to convert today's date to yesterday's using YESTERDAY3=`perl -e '@y=localtime(time()-86400); printf "%04d/%02d/%02d",$y+1900,$y+1,$y;$y;'` And once it is done I am trying to using the yesterday date in a grep command to... (3 Replies)
Discussion started by: nithinankam
3 Replies

4. What is on Your Mind?

Tennis - Wimbledon 2012

For those of you watching Wimbledon you already know that Rafael Nadal will not be in the final. There is an open event in the Event Prediction Forum. Place your bits on the guys left. This event closes on Sunday 8th July 2012. (0 Replies)
Discussion started by: ni2
0 Replies

5. Post Here to Contact Site Administrators and Moderators

Event Prediction - Euro 2012

Please add this new "event". (10 Replies)
Discussion started by: ni2
10 Replies

6. Shell Programming and Scripting

How do i compare two dates with format Jan 01, 2012 and Jan 00 2012

I need to be able to compare dates in the format of Jan 10, 2012 and Jan 10 2012. (Notice one has a comma). Then I need to find the date that is 7 days before those dates if they are equal. How can I do this in Bash. Thank ahead (4 Replies)
Discussion started by: ojthejuice
4 Replies
Login or Register to Ask a Question