Code Blog

Displaying 1-1 of 1 result.
2015/03/16 Ruby

Ruby script below:

puts "match email addresses"

input=File.open("datasheet1.tsv","r")

out_file = File.new("out.csv", "w")
ut_file = File.new("correction.csv", "w")

input.each{|line|

	# strip all commas
	line = line.gsub(/\,/,"")

    keys=line.split("\t")
    
    #puts(keys[3])

    if keys[0] == ""
    	keys[0] = keys[1]
    end

    a=/^[a-zA-Z0-9._%+-][email protected][a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.match(keys[3])
    if not a
    	#puts(line)
		#out_file.puts(line)
		ut_file.puts(keys.join(','))
		keys[3] = ""

    end    

    theline = keys.join(',')

    out_file.puts(theline)

}

out_file.close
ut_file.close