bash backtick variable simple script

Bash shell questions
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

bash backtick variable simple script

Post by MigrationUser »

21 Feb 2012 17:46
jaffamuffin

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:
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: Select all

       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

date +%Y-%m-%d -d "Feb 19"

i get:

2012-02-19

so how do i do it?

----------------------------

#2 28 Feb 2012 12:37
jaffamuffin


After 48 views and no replies, I thought I'd put you out of your misery.

the line

Code: Select all

     sqldate=`date +%Y-%m-%d -d $logdate`
should read

Code: Select all

     sqldate=`date +%Y-%m-%d -d "$logdate"`
I obvioulsy hadn't tried that but was sure I had. oh well/
Post Reply