我面对的是一个包含多个bibtex实例的文本文件
@article{Lindgren1989Resonant,
abstract = {Using a simple model potential, a truncated image barrier, for the
Al(111) surface, one obtains a resonant bound surface state at an energy
that agrees surprisingly well with recent observations by inverse
photoemission.},
author = {Lindgren and Walld\'{e}n, L.},
citeulike-article-id = {9286612},
citeulike-linkout-0 = {http://dx.doi.org/10.1103/PhysRevB.40.11546},
citeulike-linkout-1 = {http://adsabs.harvard.edu/cgi-bin/nph-bib\_query?bibcode=1989PhRvB..4011546L},
doi = {10.1103/PhysRevB.40.11546},
journal = {Phys. Rev. B},
keywords = {image-potential, surface-states},
month = dec,
pages = {11546--11548},
posted-at = {2011-05-12 11:42:49},
priority = {0},
title = {Resonant bound states for simple metal surfaces},
url = {http://dx.doi.org/10.1103/PhysRevB.40.11546},
volume = {40},
year = {1989}
}我想要擦除抽象字段,它可以跨越一行或多行(就像上面的例子)。我试着以下面的方式使用sed
sed "/^\s*${field}.*=/,/},?$/{
d
}" file其中file是包含上述bibtex代码的文本文件。但是,此命令的输出仅为
@article{Lindgren1989Resonant,很明显,sed匹配的是最终的},但是如何让它与抽象值的结束括号匹配呢?
发布于 2011-11-16 23:39:20
这可能对你有用:
sed '1{h;d};H;${x;s/\s*abstract\s*=\s*{[^}]*}\+,//g;p};d' file这会将整个文件放入保留空间,然后删除abstract字段
解释:
在第一行上,将保留空间( HS )替换为当前行,将所有后续行附加到HS。在遇到最后一行时,切换到HS并替换所有出现的摘要字段,然后打印出文件。注意:删除所有通常会打印出来的行。
发布于 2011-11-16 23:31:07
这条awk线路对你有效吗?
awk '/abstract *= *{/{a=1} (a && /} *,$/){a=0;next;}!a' yourInput发布于 2011-11-16 23:36:51
sed中的地址以一种奇怪的方式匹配:
addr2可以在addr1之前匹配,这就是您在表达式中所经历的!使用多个块。
https://stackoverflow.com/questions/8154037
复制相似问题