Delimited Data and the Command Line

Not all of our processing of delimited data will be quite so formal as reading from TSV-formatted files on our disk, though. Sometimes, text is delimited in a more casual way: pipe symbols that separate two different values in the output of a command, for example, or even just the spaces that separate words in any passage of text.

In Chapter 3, Shell One-Liners, we discovered how to use Ruby in ad hoc, write-once pipelines to filter and transform text. We can do the same with delimited data, too, and just like with plain text Ruby offers some helpful shortcuts that make doing so easy.

The first way that we can get Ruby to help us when processing delimited text is by passing the -F option to the Ruby interpreter. ...

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.