#!/bin/bash
# Merge all revised BMC1 files into one, stripping the per-file H1 titles
# Output: Buddist-Monastic-Code-I-Ver-1.md

REVISED="/home/tuan-nguyen/.openclaw/workspace/Buddist-Monastic-Code-1/revised"
OUTPUT="$REVISED/../Buddist-Monastic-Code-I-Ver-1.md"

> "$OUTPUT"  # Truncate/create

files=$(ls "$REVISED"/buddhistmonasticcode_vi_*.md 2>/dev/null | sort)
count=0

for f in $files; do
    count=$((count + 1))
    echo "Processing: $(basename $f)"

    if [ $count -eq 1 ]; then
        # First file: skip the H1 title line, keep everything else
        tail -n +2 "$f" >> "$OUTPUT"
    else
        # Subsequent files: skip the H1 line (# Bản dịch...)
        tail -n +2 "$f" >> "$OUTPUT"
    fi
done

echo ""
echo "=== DONE ==="
echo "Files merged: $count"
echo "Output: $OUTPUT"
wc -l "$OUTPUT"
