File.open('error.csv', 'a+') do |f| File.open('out.log').each do |line| if line.start_with? "检测出错" m = /检测出错: (.*), 原因: (.*)/.match(line) puts "\"\",\"#{m[1]}\",\"#{m[2]}\"" f.puts "\"\",\"#{m[1]}\",\"#{m[2]}\"" elsif line.start_with? "未发现附件" m = /(.+?):Person{uid='(.*)', name='(.*)', downloadUrl=''}/.match(line) puts "\"#{m[2]}\",\"#{m[3]}\",\"#{m[1]}\"" f.puts "\"#{m[2]}\",\"#{m[3]}\",\"#{m[1]}\"" end end end