Are you saying that the input is a text file, as will be the output? Do you have an example input file?

Wht do you have multiple pairs per row, why not one pair per row?