Awk Conditional

Hi Guys,
i have this files:
xyz20080716.log
opqrs20080716.log
abcdef20080716.log
xyz20080717.log
oprs20080717.log
abcde20080717.log

currentdate: 20080717.log
I want to make script to zip the file for past day. Can anyone help for this? i've just learn awk scripting & still confused with it.
Here's the script i make, but it's not working. any comment is very welcome.

#!/bin/bash
tgl1=`date +"%Y%m%d"
awk -F'.' '{tgl = substr($1,length($1)-7)
if (tgl1 ~ tgl) {print "OK"}
}' $1

Hi Jaduk, I read your blog & came up with this.
It's working.

ls *.log | gzip `awk -F'.' '/20080716/{print}'`

Thankyou :slight_smile:

Got another trouble, when i'm trying to insert the comparison date by using $tgl1 it won't run. what's wrong?

tgl1=`date +"%Y%m%d"`
ls *.log | gzip `awk -F'.' '/$tgl1/{print}'`

Try:

tgl1=`date +"%Y%m%d"`
ls *.log | gzip `awk -F'.' -v re=$tgl1 '$0 ~ re {print}'`

The single quotes around the awk script prevent the $tgl1 var from being evaluated.