I have a file:
@Book{gjn2011ske,
author = {Grzegorz J. Nalepa},
title = {Semantic Knowledge Engineering. A Rule-Based Approach},
publisher = {Wydawnictwa AGH},
year = 2011,
address = {Krak\'ow}
}
@article{gjn2010jucs,
Author = {Grzegorz J. Nalepa},
Journal = {Journal of Universal Computer Science},
Number = 7,
Pages = {1006-1023},
Title = {Collective Knowledge Engineering with Semantic Wikis},
Volume = 16,
Year = 2010
}
I want to improve the regular expression that only removed the first line. Note: The record separator RS="}\n" can not be changed.
I tried:
awk 'BEGIN{ RS="}\n" } {gsub(/@.*,/,"") ; print }' file
I want to print the result:
author = {Grzegorz J. Nalepa},
title = {Semantic Knowledge Engineering. A Rule-Based Approach},
publisher = {Wydawnictwa AGH},
year = 2011,
address = {Krak\'ow}
Author = {Grzegorz J. Nalepa},
Journal = {Journal of Universal Computer Science},
Number = 7,
Pages = {1006-1023},
Title = {Collective Knowledge Engineering with Semantic Wikis},
Volume = 16,
Year = 2010
Thank you for your help.
EDIT:
My proposed solution:
awk 'BEGIN{ RS="}\n" }{sub(",","@"); sub(/@.*@/,""); print }' file
It’s hard to accomplish what you want with the specified
RSsetting (because theaddress = {Krak\'ow}has an extra record ending). I’d rather go with:See it in action here.
EDIT I don’t know why it must be with a regexp solution, could you please explain it?
Anyway, yet another (working, see here) solution which uses regexp(s), but not the ones you are expecting.:
One more, with a much simpler regexp, but it fails, with the “
address” line as the last}will be removed with yourRS, and it will print a final}…