Question: I have log file in tomcat logs and I want to write a script to merge last 7 days log files.

Log file names `catalina.2015-04-23.log`, `catalina.2015-06-05.log`, `catalina.2015-06-04.log`.

Answer: 
This will produce the merged log file for 1 week

```
for a in `seq 6 -1 0`;
do
    dt=`date "+%F" --date=" -"$a" days"`;
    f=$dt".log";
    cat $f >> "1_week.log";
done;

```
For avoiding to use the explicit date, I assume that the files have been last modified on the date they are logging, allowing to use `find` and a one-liner for this:

```
find . -name '*catalina*' -daystart -mtime -6 -mtime +0 -exec cat '{}' >> this_weeks_logs.log \; 

```

Explanation:

Find all files in local folder `.` , with `-name` fragment `catalina`.
Take files that have been alternated a maximum of 6\*24 hours ago `-mtime -6` and a minimum of 0 hours ago `-mtime +0` (making it a 7 day interval), however start counting the hours from beginning of this day `-daystart` (i.e. today 00:00:00) - to make sure we start from yesterday to a week ago. Then con`cat`enate the files into `this_weeks_logs.log`

More on the time range for the `-mtime` option can be found [here](http://www.gnu.org/software/findutils/manual/html_mono/find.html#Time)