# bib-strip.awk - remove entries by key, preserving all other bytes # # Requires bib-parse.awk. Variables (set with -v): # keys - comma-separated list of entry keys to remove # keyfile - file with one key per line, for key lists too large to # pass on the command line; merged with keys # # Unlike bib-select.awk, which re-emits entries canonically, this # splices the matched entries' source spans out of the input and # leaves everything else - comments, formatting, @string blocks - # byte-for-byte intact. Used by bib-add -f so that replacing one # entry never rewrites the rest of the database. # # This END block runs after bib-parse.awk's (END blocks execute in # the order their files are given to awk), so the spans recorded by # the hooks below are complete by the time output happens. BEGIN { bib_strip_n = split(keys, bib_strip_k, ",") for (bib_strip_i = 1; bib_strip_i <= bib_strip_n; bib_strip_i++) BIB_DROP[bib_strip_k[bib_strip_i]] = 1 if (keyfile != "") { while ((getline bib_strip_line < keyfile) > 0) BIB_DROP[bib_strip_line] = 1 close(keyfile) } } function bib_pass(raw) { } function bib_entry(type, key) { if (key in BIB_DROP) { BIB_NSPAN++ BIB_SPAN_S[BIB_NSPAN] = BIB_START BIB_SPAN_E[BIB_NSPAN] = BIB_END } } END { i = 1 for (j = 1; j <= BIB_NSPAN; j++) { printf "%s", substr(bib_buf, i, BIB_SPAN_S[j] - i) i = BIB_SPAN_E[j] # swallow the whitespace that followed the removed entry while (i <= length(bib_buf) && substr(bib_buf, i, 1) ~ /[ \t\r\n]/) i++ } printf "%s", substr(bib_buf, i) }