Date Conversion on output string from awk


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Date Conversion on output string from awk
# 1  
Old 08-16-2010
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  
Old 08-17-2010
If you don't have to worry about portability, and the date command installed on your system supports the -d option, this will work:

Code:
date -d "May 24 2010"  "+%Y/%m/%d"

You can incorporate that with your awk programme to convert your string. I'm not a POSIX expert, but I am fairly certain that this is notstandard at all, so go with caution if you decide on this route.
# 3  
Old 08-18-2010
Smilie Thanks
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

String to Date conversion

Hi, I have a String say 20131224 which represents a date. I want to to subtract 1 day from this. Any idea how can i do this on AIX. (1 Reply)
Discussion started by: RahulM
1 Replies

3. 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

4. Shell Programming and Scripting

awk string to number conversion

Can someone explain whats happening here: $ awk 'BEGIN {print (2.5 - 1)}' 1,5 2.5 - 1 is correctly calculated to 1,5 (using european locale) $ echo "2.5" | awk '{temp = $1 - 1; print temp}' 1 If i now pipe the string 2.5 through awk it seems at it truncates 2.5 to 2? What's the... (4 Replies)
Discussion started by: beow
4 Replies

5. Shell Programming and Scripting

Date command output conversion

hi all, i need to measure time difference between the time a process started, to the time it ended. i am assuming the following are the steps: 1. output 'date' command at start time 2. output 'date' command at end time 3. subtract the two question is, how do i subtract the two time... (4 Replies)
Discussion started by: rathajs
4 Replies

6. Shell Programming and Scripting

awk: round output or delimit output of arithmatic string

I have a file with the following content. > cat /tmp/internetusage.txt 6709.296322 30000 2/7/2010 0.00I am using the following awk command to calculate a percentage from field 1 and 2 from the file. awk '{ print $1/$2*100 }' /tmp/internetusage.txt This outputs the value "22.3643" as a... (1 Reply)
Discussion started by: jelloir
1 Replies

7. Shell Programming and Scripting

Date string conversion within a file

Hi, I have a log file that contains information along the lines of the following: ========= jobnumber 322761 start_time Tue May 19 19:42:37 2009 end_time Tue May 19 20:11:28 2009 failed 0 ========= jobnumber 322762 start_time Tue May 19 19:39:51 2009 end_time ... (4 Replies)
Discussion started by: chrissycc
4 Replies

8. Shell Programming and Scripting

Conversion of Exponential to numeric in awk- not correct output

Hi All, I have 1 million records file. Using awk, I am counting the number of records. But as the number is huge, after crossing a number, awk is displaying it in exponential format. At the end, I need to verify this count given by awk with expected count. But as it is in exponential format,... (3 Replies)
Discussion started by: ssunda6
3 Replies

9. Shell Programming and Scripting

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 Replies)
Discussion started by: charandevu
2 Replies

10. Shell Programming and Scripting

String Conversion in awk

I am porting a awk script from Windows to unix I_SALE_MEDIA=$67 if ((I_VOID_FLAG == "Y") && (I_SALE_MEDIA == 0)) NOW consider the case where I_SALE_MEDIA i.e $67 is "000" The above comparison works fine in Windows , but to make it work in Unix , I had to change the above as follows : ... (3 Replies)
Discussion started by: rohanrege
3 Replies
Login or Register to Ask a Question