bash backtick variable simple script

Soldato
Joined
22 Aug 2005
Posts
8,845
Location
Clydebank
Hi all

trying to parse a log file into a nice csv file for import into mysql, one aspect of this is converting a data of the form Feb 19 into a 2012-02-19 format.

This is my line of data:
Code:
Feb 19 18:42:16 sftp internal-sftp[12067]: session opened for local user galbraith from [xx.xxx.xxx.xxx]

This is my code:

Code:
...
       logdate=`echo $LINE|cut -d" " -f1-2`
       sqldate=`date +%Y-%m-%d -d $logdate`
...

But I can not get sqldate to 'take' the value of $logdata and evaluate it against date. If I literally type
Code:
date +%Y-%m-%d -d "Feb 19"
i get:
Code:
2012-02-19

so how do i do it?
 
Try this:

Code:
sqldate=`date +%Y-%m-%d -d "$logdate"`

without those quotes I get

date: extra operand `19', meaning that it is interpretting the space between Feb and 19 as an additional argument.
 
Back
Top Bottom