I am not looking from ls.
Here is my code and I want to fetch year and month from the file which I have alread read.
cd Log_dir
for f in *.log
do
let cnt="cnt + 1"
logfilename=$f
Log "Log file Name $logfilename"
logfile=`basename $logfilename .log`
Log "logfile without extension $logfile"
logfiledate=$`awk -F_ '{print $(NF-1)}' $logfile`
Log "logfiledate $logfiledate"
done
Log "Total file count $cnt"
The problem is I am not getting logfiledate.
Please let me know how can I extract this field. My datetime in file is last 15 characters. f_CCYYMMDD_HHMMSS.
Just want to get CCYYMM from the file.
Thanks and Regards\
Dgmm
cd Log_dir
for f in *.log
do
let cnt="cnt + 1"
logfilename=$f
Log "Log file Name $logfilename"
logfile=${logfilename%.*}
Log "logfile without extension $logfile"
logfiledate=$(echo $logfile | awk -F_ '{print $(NF-1)}')
Log "logfiledate $logfiledate"
done
Log "Total file count $cnt"