phhbjs #!/bin/bash a=1 while IFS= read -r i do if [[ -z "$i" ]]; then continue fi # 转义特殊字符 escaped_i=$(printf '%s\n' "$i" | sed -e 's/[][()+\.*^$/]/\\&/g') sed -i '' -E "s@^($escaped_i)@第 $a 章 \1@" 2.txt a=$((a + 1)) done < 1.txt