回答編集履歴

6

余計なスペースが出力されていたので修正

2023/11/21 10:30

投稿

arcxor
arcxor

スコア2859

test CHANGED
@@ -31,7 +31,7 @@
31
31
  #!/bin/bash
32
32
 
33
33
  lines=$(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)
34
- lines=$(echo "$lines" | awk '{ map[$1] = map[$1] "\t" $3 " " $2 } END { for(key in map) print key, map[key] }' | sort -V)
34
+ lines=$(echo "$lines" | awk '{ map[$1] = map[$1] "\t" $3 " " $2 } END { for(key in map) print key map[key] }' | sort -V)
35
35
 
36
36
  IFS=$'\n'
37
37
  for line in $(echo "$lines"); do

5

高速化しました

2023/11/20 16:52

投稿

arcxor
arcxor

スコア2859

test CHANGED
@@ -30,33 +30,17 @@
30
30
  ```bash
31
31
  #!/bin/bash
32
32
 
33
+ lines=$(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)
34
+ lines=$(echo "$lines" | awk '{ map[$1] = map[$1] "\t" $3 " " $2 } END { for(key in map) print key, map[key] }' | sort -V)
35
+
33
36
  IFS=$'\n'
34
-
35
- declare -A map
36
- declare -a map_keys
37
- lines=''
38
-
39
- for f in $(find . -type f); do
40
- lines+="$f"$'\n'
41
- done
42
-
43
- for time_path in $(echo "$lines" | xargs ls -l --time-style='+%Y-%m' | awk '{print $6, $7}' | sort); do
44
- time=$(echo "$time_path" | awk '{print $1}')
45
- path=$(echo "$time_path" | awk '{print $2}')
46
- rows=$(wc -l "$path" | awk '{print $1}')
47
- if [ -n "${map[$time]}" ]; then
48
- map["$time"]+=$'\t'
49
- else
50
- map_keys+=("$time")
51
- fi
52
- map["$time"]+="$rows $path"
53
- done
54
-
55
- for time in "${map_keys[@]}"; do
37
+ for line in $(echo "$lines"); do
56
- lines=$(echo "${map[${time}]}" | tr $'\t' $'\n')
38
+ strs=$(echo "$line" | tr $'\t' $'\n')
39
+ time=$(echo "$strs" | head -n 1)
40
+ strs=$(echo "$strs" | tail -n +2)
57
- sum=$(echo "$lines" | awk '{s += $1} END {print s}')
41
+ sum=$(echo "$strs" | awk '{s += $1} END {print s}')
58
42
  echo "==== $time: $sum"
59
- echo "$lines"
43
+ echo "$strs"
60
44
  echo
61
45
  done
62
46
  ```

4

main.sh を修正

2023/11/20 12:01

投稿

arcxor
arcxor

スコア2859

test CHANGED
@@ -36,11 +36,11 @@
36
36
  declare -a map_keys
37
37
  lines=''
38
38
 
39
- for f in $(find . -type f | sort); do
39
+ for f in $(find . -type f); do
40
- lines+=$(ls -l --time-style='+%Y-%m' "$f" | awk '{print $6, $7}')$'\n'
40
+ lines+="$f"$'\n'
41
41
  done
42
42
 
43
- for time_path in $(echo "$lines" | sort); do
43
+ for time_path in $(echo "$lines" | xargs ls -l --time-style='+%Y-%m' | awk '{print $6, $7}' | sort); do
44
44
  time=$(echo "$time_path" | awk '{print $1}')
45
45
  path=$(echo "$time_path" | awk '{print $2}')
46
46
  rows=$(wc -l "$path" | awk '{print $1}')

3

find の引数を修正

2023/11/20 04:46

投稿

arcxor
arcxor

スコア2859

test CHANGED
@@ -36,7 +36,7 @@
36
36
  declare -a map_keys
37
37
  lines=''
38
38
 
39
- for f in $(find -type f | sort); do
39
+ for f in $(find . -type f | sort); do
40
40
  lines+=$(ls -l --time-style='+%Y-%m' "$f" | awk '{print $6, $7}')$'\n'
41
41
  done
42
42
 

2

main.sh を修正

2023/11/20 04:36

投稿

arcxor
arcxor

スコア2859

test CHANGED
@@ -36,18 +36,14 @@
36
36
  declare -a map_keys
37
37
  lines=''
38
38
 
39
- for f in $(find . -type f | sort); do
39
+ for f in $(find -type f | sort); do
40
- time_path=$(ls -l --time-style='+%Y-%m' "$f" | awk '{print $6, $7}')
40
+ lines+=$(ls -l --time-style='+%Y-%m' "$f" | awk '{print $6, $7}')$'\n'
41
+ done
42
+
43
+ for time_path in $(echo "$lines" | sort); do
41
44
  time=$(echo "$time_path" | awk '{print $1}')
42
45
  path=$(echo "$time_path" | awk '{print $2}')
43
46
  rows=$(wc -l "$path" | awk '{print $1}')
44
- lines+="$time $path $rows"$'\n'
45
- done
46
-
47
- for time_path_rows in $(echo "$lines" | sort); do
48
- time=$(echo "$time_path_rows" | awk '{print $1}')
49
- path=$(echo "$time_path_rows" | awk '{print $2}')
50
- rows=$(echo "$time_path_rows" | awk '{print $3}')
51
47
  if [ -n "${map[$time]}" ]; then
52
48
  map["$time"]+=$'\t'
53
49
  else

1

find の引数を修正

2023/11/19 17:45

投稿

arcxor
arcxor

スコア2859

test CHANGED
@@ -36,7 +36,7 @@
36
36
  declare -a map_keys
37
37
  lines=''
38
38
 
39
- for f in $(find -type f | sort); do
39
+ for f in $(find . -type f | sort); do
40
40
  time_path=$(ls -l --time-style='+%Y-%m' "$f" | awk '{print $6, $7}')
41
41
  time=$(echo "$time_path" | awk '{print $1}')
42
42
  path=$(echo "$time_path" | awk '{print $2}')