Parsing a TSV

Let’s imagine we have a spreadsheet that represents our personal expenditures. We want to keep track of what we buy, how much it costs, and where we bought it. So we set up a spreadsheet in which each row (or record) represents a purchase, and in which the columns (or fields) represent the item name, the price, and the retailer from which it was bought.

We happily record our data, and all is well. But the list soon becomes unwieldy, and it’s difficult to analyze the data. We might want to find out our most expensive ever item, for example, or calculate the average cost of an item from a particular retailer. If we get the data into Ruby, these calculations will be straightforward, so let’s find out how to do that.

Our first step ...

Get Text Processing with Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.