init.sh
bash
1#!/bin/bash
2
3mkdir -p testdir/dir
4
5for i in $(seq 1 9); do
6 for k in $(seq 1 $i); do
7 echo $k >> testdir/${i}.txt
8 done
9done
10
11touch -t 202201010000 testdir/1.txt
12touch -t 202201020000 testdir/2.txt
13touch -t 202301030000 testdir/3.txt
14touch -t 202301040000 testdir/4.txt
15touch -t 202301050000 testdir/5.txt
16touch -t 202302060000 testdir/6.txt
17touch -t 202302070000 testdir/7.txt
18touch -t 202303080000 testdir/8.txt
19touch -t 202304090000 testdir/9.txt
20
21for i in $(seq 5 9); do
22 mv testdir/${i}.txt testdir/dir
23done
main.sh
bash
1#!/bin/bash
2
3lines=$(join -j2 -o '1.1 1.2 2.1' <(find . -type f -printf '%TY-%Tm %p\n' | sort -k2) <(find . -type f | xargs wc -l | sort -k2) | sort -V)
4lines=$(echo "$lines" | awk '{ map[$1] = map[$1] "\t" $3 " " $2 } END { for(key in map) print key map[key] }' | sort -V)
5
6IFS=$'\n'
7for line in $(echo "$lines"); do
8 strs=$(echo "$line" | tr $'\t' $'\n')
9 time=$(echo "$strs" | head -n 1)
10 strs=$(echo "$strs" | tail -n +2)
11 sum=$(echo "$strs" | awk '{s += $1} END {print s}')
12 echo "==== $time: $sum"
13 echo "$strs"
14 echo
15done
output
sh
1cd testdir
2../main.sh
text
1==== 2022-01: 3
21 ./1.txt
32 ./2.txt
4
5==== 2023-01: 12
63 ./3.txt
74 ./4.txt
85 ./dir/5.txt
9
10==== 2023-02: 13
116 ./dir/6.txt
127 ./dir/7.txt
13
14==== 2023-03: 8
158 ./dir/8.txt
16
17==== 2023-04: 9
189 ./dir/9.txt