#gawk -f ~/src/awk/awk2wp.awk goal=Menzies ~/wp/refs.bib BEGIN { print "\n" } END { print "" } BEGIN { RS="@"; FS="\n"; IGNORECASE=1; s2a(Fields, "class chapter title year author booktitle journal " \ "editor note publisher institution volume number " \ "day month pages isbn "\ "abstract annote howpublished keywords"); s2k(Mark, "pages volume number isbn"); s2k(Skip, "abstract annote howpublished keywords"); s2l(Class, "hO Miscellaneous hB Chapter hC Conference hP Conference "\ "hJ Journal hS Workshop hW Workshop hE Editorial "\ "hX Workshop hN Conference hQ Conference hD Draft hU Unpublished "\ "hT Thesis"); } function s2a(a,s, n) { n=split(s,a," "); a[0]=n; } function s2k(k,s, i,n) { n=split(s,a," "); for(i=1;i<=n;i++) k[a[i]]=a[i]; } function s2l(l,s, i,n) { n=split(s,a," "); for(i=1;i<=n;i=i+2) l[a[i]]=a[i+1]; } function trim(s) { sub(/^[ \t]*/,"",s); sub(/[ \t]*$/,"",s); return s; } function clean(s) { s=trim(s); q="\"" s=gensub(/\\url{([^}]*)}/,"\\1","g",s) gsub(/[{}\"\'\\]/,"",s); gsub(/,$/,"",s); gsub(/\r/,"",s); gsub(/&/,"&",s); return s; } $0 ~ goal {eat()} function eat( what,a,n,f,i,j,value,key,me,tmp,pre,post) { for(i=2;i<=NF;i++) { $i=clean($i); if ($i ~ /^[ \t]*$/ ) continue; for(j=1;j<=Fields[0];j++) { if ( match($i,"^[ \t]*" Fields[j] "[ \t]*=[ \t]*" )) { $i=substr($i,RSTART+RLENGTH); key=Fields[j]; break; } } value[key]=value[key] " " $i; }; prefix="NoClass"; print "\t"; for(j=1;j<=Fields[0];j++) { key=Fields[j]; if (key in value) if ( ! (key in Skip ) ) { if (key=="class") { n=split(value[key],a,/ /); for(i=1;i<=n;i++) if (a[i] in Class) { what=Class[a[i]]; prefix=what ; print "\t\t"trim(prefix)""; break; } } else { tmp=value[key]; sub(/,[\t ]*$/,"",tmp) pre=post="" if(key=="note") { pre=""}; print "\t\t<" key ">"pre; if ( key in Mark ) print "\t\t\t"key; print "\t\t\t"tmp; print "\t\t"post""; } } } print "\t"; }