forked from OpenWebGAL/WebGAL_Doc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombine.sh
More file actions
27 lines (22 loc) · 825 Bytes
/
combine.sh
File metadata and controls
27 lines (22 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
# 遍历所有子目录(包括当前目录)
find . -type d | while read -r dir; do
# 从目录路径中提取目录名,替换 '/' 为 '_'
dir_name=$(basename "$dir")
output_file="$dir/${dir_name}_combined.md"
# 检查并删除已存在的输出文件
if [ -f "$output_file" ]; then
rm "$output_file"
fi
# 在每个目录中遍历 .md 文件
find "$dir" -maxdepth 1 -name '*.md' | while read -r file; do
# 确保文件存在且不是目录
if [ -f "$file" ]; then
echo "Merging $file into $output_file"
cat "$file" >> "$output_file"
# 在每个文件之间加入换行以分隔内容
echo -e "\n" >> "$output_file"
fi
done
done
echo "All .md files in each directory have been combined."