Small Tools


CSV is a great format for spreadsheets; it's simple, portable, and easy to read. The only problem is that the delimiter character that defines the format, the comma, is rather common in actual data, meaning that it requires special treatment that can be a bit of a pain in the neck.

In my case, I wanted to be able to pull rows, columns, and individual cells from a spreadsheet using awk. AWK and CSV are a near perfect match, with AWK's entire structure being based around lines of input delimited by some special character. AWK, though, does not have any way to handle the commas that are not delimiters, i.e. the ones in cells surrounded by double quotes.

Fortunately, AWK itself can be used to make its own perfect spreadsheet format. This script replaces all of the delimiting commas in a CSV spreadsheet with a character that can be specified by the user, so you can always pick a delimiter that won't appear in the data, and you don't have to worry about special cases with double quotes.