My question is similar to this. Basically there is a CSV file but with duplicate PIDs, but I cannot do the .uniq as this:
File.open("new.csv", "w+") { |file| file.puts File.readlines("old.csv").uniq }
since the lines are different. I’m new to Ruby and was wondering if there was an elegant way to remove the entire line just based on the first column? Or do I have to go through each row and look for duplicate PIDs?
You can pass
uniqa block to specify on which requirement it will remove the duplicated elements.As explained in the
uniqdocumentation.Replace the
/^\d+/regular expression by anyone that suits you.