根据年份提取 bibtex 条目

Extract bibtex entries based on the year

好的,我得到了包含多个条目的 file.bib 文件,例如

@Book{Anley:2007:shellcoders-handbook-2nd-ed,
  author =   {Chris Anley and John Heasman and Felix Lindner and Gerardo
    Richarte},
  title =    "{The Shellcoder's Handbook}",
  publisher =    {Wiley},
  year =     2007,
  edition =      2,
  month =    aug,
}

在那里您可以找到 "year = 2007" 行。我的任务是过滤掉大于 2020 ($currentyear) 或小于 1900 ($minyear) 的年份,结果应该也是 "may" 月份的输出,它位于 [=17] 后面=] 该文件中的行。 (这是管理员的错误)。 (顺便说一句,文件超过 4000 行)。

这个最好用awk。与您的台词类似,它会显示为:

awk -v t1="1900" -v t2="$(date "+%Y")" \
    '!match([=10=],/year.*=.*/){next}
     {t=substr(RSTART,RLENGTH)
      match(t,/[0-9][0-9][0-9][0-9]/)
      y=substr(RSTART,RLENGTH)
     }
     (y > t1) && (y <= t2) { print y }' file