A spectral survey in the 1mm wavelength range was undertaken in the long-period comets C/2012 F6 (Lemmon) and C/2013 R1 (Lovejoy) using the 30m telescope of the Institut de radioastronomie millimetrique (IRAM) in April and November-December 2013. We report the detection of ethylene glycol (CH_2OH)_2 (aGg' conformer) and formamide (NH_2CHO) in the two comets. The abundances relative to water of ethylene glycol and formamide are 0.2-0.3% and 0.02% in the two comets, similar to the values measured in comet C/1995 O1 (Hale-Bopp). We also report the detection of HCOOH and CH_3_CHO in comet C/2013 R1 (Lovejoy), and a search for other complex species (methyl formate, glycolaldehyde).