awk script for date conversion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk script for date conversion
# 1  
Old 04-08-2008
awk script for date conversion

hi
awk script for dd/mm/yyyy to yyyymmdd
awk script for dd-mon-yyyy to yyyymmdd
awk script for dd-mm-yyyy to yyyymmdd formate
..............urgent.............

Thanks in advanced
# 2  
Old 04-08-2008
please stop to post the same question on multiple threads!
# 3  
Old 04-08-2008
Ok, here's an example, it's up to you now to figure it out and fit it as desired.
And please stop bumping up and double posting questions as a loser or you'll be banned!

Code:
echo "01-JUL-2007" | 
awk 'BEGIN {
  FS=OFS="-"
  split("JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC",m,",")
}
{for(i=1;i<13;i++) {
  if($0 == m[i]){$0=sprintf("%02d", i)}}
}1'

Regards

Last edited by Franklin52; 04-08-2008 at 08:44 AM.. Reason: edit code field must be $0 instead of $2
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Date format conversion how to change this from using nawk to awk

Hi, I have a file where I need to change the date format on the nth field from DD-MM-YYYY to YYYY-MM-DD so I can accurately sort the record by dates From regex - Use sed or awk to fix date format - Stack Overflow, I found an example using nawk. Test run as below: $: cat xyz.txt A ... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Date Conversion

Hi I want to convert date from one format to the other i.e. From Thu Mar 6 15:57:39 2014 To 2014-03-06 15:57:39 Is there any direct command to implement this ? (1 Reply)
Discussion started by: tostay2003
1 Replies

3. Shell Programming and Scripting

awk Flat File Conversion Script

In awk how would I flatten input.txt to output.txt? Input: givenname: Darth sn: Vadar mail: d.vadar@deathstar.com uid: dv12345 orclguid: 1234567890 givenname: Carlito sn: Brigante mail: c.brigante@paradise.com uid: cb12345 orclguid: 2134567890 Output: ... (3 Replies)
Discussion started by: u20sr
3 Replies

4. AIX

Date Conversion

Hi, I would like to change the incoming date format (Jun 25 2010) to 06/25/2010. I have seen date "dconv" function but i am not sure how that works. $ echo "Jun 25 2010" | nawk ' { months=" JanFebMarAprMayJunJulAugSepOctNovDec";date=$1;month=index(months,substr($1,1,3))/3; ... (3 Replies)
Discussion started by: Prashanth B
3 Replies

5. Shell Programming and Scripting

Most vexing: Sed or Awk scripting for date conversion needed

Hi, I have some files being sent to me that have dates in them in this format: from 1/8/2011 15:14:20 and I need the dates in this format (mysql date format) To 2011-01-08 15:14:20 all I have so far is the regexp that detects the format: sed -r -e 's@\1/\2/\3\4\5\6]::$@do... (7 Replies)
Discussion started by: Astrocloud
7 Replies

6. Shell Programming and Scripting

Shell script for Date conversion from mm/dd/yy to mm/dd/yyyy

Seek help in coverting date from mm_dd_yy to mm_dd_yyyy. I get a date in a file some thing file like this 09_14_11.pdf Need to convert the same to 09_14_2011.pdf :wall: (9 Replies)
Discussion started by: aakishore
9 Replies

7. Shell Programming and Scripting

Julian date to Calendar date conversion

Hi all, I require to convert julian date to normal calander date in unix for eg julian date=122 now i want corresponding calander date ---------------------------------------- gr8 if give very small command/script and please explain the steps as well(imp) Thanks ... (3 Replies)
Discussion started by: RahulJoshi
3 Replies

8. UNIX for Advanced & Expert Users

Date Conversion on output string from awk

Hi, I would like to convert the output from awk function to date and print on the screen. Example : echo "Start Date: May 24 2010" | gawk -F": " '{print $2}' Output : May 04 2010 I want this to be converted to 2010/05/24 Can i use date function here and how? Thanks, Deepika (2 Replies)
Discussion started by: deepikad
2 Replies

9. Shell Programming and Scripting

Conversion of date to Julian date

Hi Gurus, Need help in Conversion of date(2007-11-30) to Julian date(YYDDD)... '+%J' 2007-11-30 to 'YYDDD' Thanks (4 Replies)
Discussion started by: SeenuGuddu
4 Replies

10. Shell Programming and Scripting

date conversion

Hi everybody: Could anybody tell me how I convert from a julian date, with shell comands, to gregorian. Thanks in advance. (2 Replies)
Discussion started by: tonet
2 Replies
Login or Register to Ask a Question