简体   繁体   English

根据年份提取 bibtex 条目

[英]Extract bibtex entries based on the year

Okay, I got the file.bib file with multiple entries such好的,我得到了包含多个条目的 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,
}

there you can find the "year = 2007" line.在那里您可以找到“year = 2007”行。 My task is to filter out the years which are greater than 2020 ($currentyear) or lower than 1900 ($minyear), the result should be a also the output of the month "may", which stands behind a "year" line in this file.我的任务是过滤掉大于 2020 ($currentyear) 或小于 1900 ($minyear) 的年份,结果也应该是“may”月份的输出,它位于“year”行后面这个文件。 (Which is a mistake by the admin). (这是管理员的错误)。 (btw the file is over 4000 lines long). (顺便说一句,文件超过 4000 行)。

It is better to use awk for this.为此最好使用 awk。 Similar to your line, it would read:与您的行类似,它会显示为:

awk -v t1="1900" -v t2="$(date "+%Y")" \
    '!match($0,/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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM