i have the following script to read the date for a file :
- get_mdate.awk
{
timestamp = substr($0, 42, 12)
month = substr(timestamp, 1, 3)
day = substr(timestamp, 5, 2)
thisyear = substr(todaydate, 1, 4)
thismonth = substr(todaydate, 5, 2)
if (month == "Jan") {
monthnum = "01"
} else if (month == "Feb") {
monthnum = "02"
} else if (month == "Feb") {
monthnum = "02"
} else if (month == "Mar") {
monthnum = "03"
} else if (month == "Apr") {
monthnum = "04"
} else if (month == "May") {
monthnum = "05"
} else if (month == "Jun") {
monthnum = "06"
} else if (month == "Jul") {
monthnum = "07"
} else if (month == "Aug") {
monthnum = "08"
} else if (month == "Sep") {
monthnum = "09"
} else if (month == "Oct") {
monthnum = "10"
} else if (month == "Nov") {
monthnum = "11"
} else if (month == "Dec") {
monthnum = "12"
}
year = substr(timestamp, 9, 4)
timeseparator = substr(timestamp, 10, 1)
if (timeseparator == ":") {
if (monthnum > thismonth) {
year = thisyear - 1
} else {
year = thisyear
}
}
printf("%04d%02d%02d\n",year,monthnum,day)
}
i will read it by
ls -tl {path_t-_read _file} | awk -f {path to read get_mdate.awk} todaydate=$todaydate
but the problems happen when the file size is too big, and the date will be shift a bit and end up read wrongly. example, as following,(the agebklog.dat) :
-rw-rw---- 1 jbdaemon bsp 999620 Jul 21 01:34 GROSS_BILLINGS.200110
-rw-rw---- 1 jbdaemon bsp 940966 Jul 21 01:34 GROSS_BILLINGS.200111
-rw-r----- 1 jbdaemon bsp 27411492 Jul 21 14:46 agebklog.dat
is there another solution to solve this? tq
- get_mdate.awk
{
timestamp = substr($0, 42, 12)
month = substr(timestamp, 1, 3)
day = substr(timestamp, 5, 2)
thisyear = substr(todaydate, 1, 4)
thismonth = substr(todaydate, 5, 2)
if (month == "Jan") {
monthnum = "01"
} else if (month == "Feb") {
monthnum = "02"
} else if (month == "Feb") {
monthnum = "02"
} else if (month == "Mar") {
monthnum = "03"
} else if (month == "Apr") {
monthnum = "04"
} else if (month == "May") {
monthnum = "05"
} else if (month == "Jun") {
monthnum = "06"
} else if (month == "Jul") {
monthnum = "07"
} else if (month == "Aug") {
monthnum = "08"
} else if (month == "Sep") {
monthnum = "09"
} else if (month == "Oct") {
monthnum = "10"
} else if (month == "Nov") {
monthnum = "11"
} else if (month == "Dec") {
monthnum = "12"
}
year = substr(timestamp, 9, 4)
timeseparator = substr(timestamp, 10, 1)
if (timeseparator == ":") {
if (monthnum > thismonth) {
year = thisyear - 1
} else {
year = thisyear
}
}
printf("%04d%02d%02d\n",year,monthnum,day)
}
i will read it by
ls -tl {path_t-_read _file} | awk -f {path to read get_mdate.awk} todaydate=$todaydate
but the problems happen when the file size is too big, and the date will be shift a bit and end up read wrongly. example, as following,(the agebklog.dat) :
-rw-rw---- 1 jbdaemon bsp 999620 Jul 21 01:34 GROSS_BILLINGS.200110
-rw-rw---- 1 jbdaemon bsp 940966 Jul 21 01:34 GROSS_BILLINGS.200111
-rw-r----- 1 jbdaemon bsp 27411492 Jul 21 14:46 agebklog.dat
is there another solution to solve this? tq