File indexing completed on 2026-04-04 08:08:15
0001
0002
0003 cat > fill.awk <<'AWK'
0004
0005 FNR==NR { a[++m] = $2; b[m] = $3; next }
0006
0007
0008 function nthpos(s, c, n, i, p) {
0009 p = 0
0010 for (i = 1; i <= n; i++) {
0011 p = index(substr(s, p + 1), c)
0012 if (p == 0) return 0
0013 p += (length(substr(s, 1, p + (p>0?0:0))) - length(substr(s, 1, p)))
0014 }
0015 return 0
0016 }
0017
0018
0019 function nthamp(s, n, i, p, q) {
0020 q = 0
0021 for (i = 1; i <= n; i++) {
0022 p = index(substr(s, q + 1), "&")
0023 if (p == 0) return 0
0024 q += p
0025 }
0026 return q
0027 }
0028
0029 {
0030 line = $0
0031
0032
0033 if (index(line, "&") && line ~ /\\\\[[:space:]]*$/) {
0034 row++
0035
0036 if (row <= m) {
0037
0038 p4 = nthamp(line, 4)
0039 if (p4 > 0) {
0040 prefix = substr(line, 1, p4)
0041 tail = substr(line, p4 + 1)
0042
0043
0044
0045 sub(/^[[:space:]]*&[[:space:]]*&/, " " a[row] " & " b[row] " ", tail)
0046
0047 line = prefix tail
0048 }
0049 }
0050 }
0051
0052 print line
0053 }
0054 AWK
0055
0056 awk -f fill.awk extra.dat table.tex > table_filled.tex