(* Getting list of notes for each species *) maintainNotes := ( notes[_] := {}; SetDirectory[dirwork]; filelist = "comments.txt"; data = Import[filelist, "Lines"]; data = Select[data, ! StringMatchQ[#, "'*'"] &]; data1 = Select[data, ! StringFreeQ[#, "'"] &]; If[data1 =!= {}, Print["Warning: ", filelist, ": some lines contain ' character: ", data1]]; data = Split[ data, ! StringMatchQ[#1, Whitespace ...] && ! StringMatchQ[#2, Whitespace ...] &]; data = Select[data, ! StringMatchQ[#[[1]], Whitespace ...] &]; data = Select[data, ! StringMatchQ[Last[#], Whitespace ... ~~ "-" ~~ Whitespace ...] &]; md = Length[data]; Print["Adding notes for ", md, " plants ..."]; namese = #[[1]] & /@ data; dups = Tally[namese]; dups = Select[dups, #[[2]] =!= 1&]; If[dups =!= {}, Print["Warning: There are duplicate names in the list of notes: ", dups // TableForm]]; names1e = Complement[namese, plantlista]; m1 = Length[names1e]; If[m1 >0, Print["Warning: There are ", m1, " plants in list of notes that are not in the plant list: ", Short[names1e, 50]]]; Do[ name = First[dat]; If[Length[dat] == 1, Print["Error: notes.txt: Length of the record should be larger than 1: ", name]]; nts = Drop[dat, 1]; nts = (StringTrim[#, (Whitespace | ".") ...] <> ".") &/@ nts; notes[name] = nts, {dat, data}]; (* Re-writing exclusion list in order of families *) filelist1 = "comments1.txt"; mnts = 0; replnotes = { "AB book" -> "a book \"The flora of Qatar\" by Ekhlas M. M. Abdel Bary (Qatar University, 2012)", "Irkaya" ->"Irkhaya (Irkaya) Farms" }; replspec = { "\"" -> """ }; lines = Table[ nts = notes[plant]; notes[plant] = StringReplace[StringReplace[#, replnotes], replspec] &/@ nts; {plant, If[nts === {}, "-", mnts = mnts + Length[nts]; nts], ""}, {plant, plantlist}]; Export[filelist1, Flatten[lines], "Lines"]; Print[mnts, " notes were written into file ", filelist1]; );