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;

```
[*Super Speedy Syslog Searcher*](https://crates.io/crates/super_speedy_syslog_searcher) can merge multiple log files into one log file, sorting log messages by datetime, and filtering by a datetime range.

(assuming you have [rust installed](https://www.rust-lang.org/tools/install))

```
cargo install super_speedy_syslog_searcher

```

then

```text
s4 catalina*log -a $(date -d "7 days ago" '+%Y-%m-%d')

```

Let `s4` parse *all* the `catalina.log` files. It will filter by the passed date range of *7 days ago* to *now*.