BEGIN { fn_count = 0 } # Match [^id]: text /^\[\^[a-zA-Z0-9_-]+\]:/ { id_start = index($0, "[^") + 2 id_end = index($0, "]:") id = substr($0, id_start, id_end - id_start) text = substr($0, id_end + 2) # Trim leading space sub(/^[ \t]+/, "", text) fn_ids[++fn_count] = id fn_texts[id] = text next } { lines[++line_count] = $0 } END { for (i = 1; i <= line_count; i++) { line = lines[i] for (j = 1; j <= fn_count; j++) { id = fn_ids[j] marker = "[^" id "]" repl = "" id "" while ((pos = index(line, marker)) > 0) { line = substr(line, 1, pos - 1) repl substr(line, pos + length(marker)) } } print line } if (fn_count > 0) { print "
" text " ↩
" print "