Is it possible to use the matched string in sed as an input to shell date command?
Hi,
I am a newbee and appreciate any help I can get. I have been spending couple of hourse searching the net to find my answer, but can not find any post that includes answer to this question.
I have a file with records having timestamp fields that include GMT offset. I want to use the sed command to replace the value on the record to a regular timestamp (without GMT offset).
for ex.
date -d '2012/11/01 00:50:22 -0800' '+%Y-%m-%d %H:%M:%S'
returns this value which is what I am looking to do:
2012-11-01 01:50:22
Except I want to perform that operation on every line of this file and apply the date command to the timestamp value. Here is a sample record:
"SB","6GV96644X48128125","","","","T0006",2012/10/03 13:08:43 -0700,"NJ"
Here is my code:
head -1 myfile | sed 's/,[0-9: /\-]\{25\},/,'"`date -d \1 '+%Y-%m-%d %H:%M:%S'`"',/
which doesn't work: it just ignores \1 and replaces the matched pattern with today's date!
"SB","6GV96644X48128125","","","","T0006",2012-11-14 01:00:00,"NJ"
I hoped that \1 would result in the matched patterns be passed to the date function and return a regular timestamp value (as in the example I provided above showing how the date functions applies the GMT offset and returns a regular stimestamp string) and would replace the old value on the record.
REally appreciate your help,
Yadam
Last edited by yadam; 11-14-2012 at 07:15 PM.
|