6.2. Foods Text files: an example
Prev | Chapter 6. Plain text Foods files, and choosing which type of Foods file to use | Next

## 6.2. Foods Text files: an example

Here is an example Foods Text file:

Example 6.1. A sample Foods Text file

    #source:name:qty:unit:date:meal:group:comment:options
    #Options: x=exact match; i=ignore case
    /home/massysett/pantry-data/master:Milk, reduced fat, fluid, 2% milkfat, with added vitamin A:1.0:cup:2007-06-30:Breakfast:Cereal and Milk::x
    /home/massysett/pantry-data/master:Papayas:1 1/2:medium
    /home/massysett/pantry-data/master:blueberries, raw:5:oz:::::i

The first thing to notice is that you can begin comments anywhere on a line with a hash mark, `#`. Pantry ignores any text after the comment symbol. Here, the first two lines are handy reminders of the syntax of the Foods Text file.

Colons separate the fields in the Foods Text file. If you need to include a colon or a hash mark in a field, you can precede it with a backslash, `\`. To include a backslash, precede it with a backslash. A single backslash followed by any character other than a backslash, colon, or hash mark generates an error.

Here is what appears in each column of the Foods Text file:

Columns in the Foods Text file
Column: 1
Contents: The source file; that is, the filename of the file holding the food that contains the nutrient and unit data for this food. It is best to include a full, absolute path specification here. You can use a relative path, but it will be resolved relative to the working directory of the pantry command when you invoke it, not relative to the directory of the text data file. This is confusing, which is why I recommend including an absolute path specification.
Column: 2
Contents: The name of the food. Pantry uses this to look up a food in the source file, which then serves as the basis for this food. This is a regular expression, unless `x` is specified in the `options` column. The search is case-sensitive unless `i` is specified in the `options` column. After looking up the food using the contents of this column and the `source` column, Pantry changes the traits of the food according to the following columns.
Column: 3
Contents: The quantity for the food.
Column: 4
Contents: The unit for the new food. The unit is selected from the food's available units. The value in this column is a regular expression, unless `x` is specified in the `options` column, and the search is case sensitive unless `i` is specified in the `options` column.
Column: 5
Contents: The `date` trait for the new food.
Column: 6
Contents: The `meal` trait for the new food.
Column: 7
Contents: The `group` trait for the new food.
Column: 8
Contents: The `comment` trait for the new food.
Column: 9
Contents: These are search options. This column may have zero, one, or two letters. `x` specifies that the search for the food name and for the unit must be an exact match, rather than a regular expression. `i` makes searches case insensitive.

If you only need to use some of the columns, you can leave out trailing columns. The only columns that you must specify are the first two, for the source and the food name.

You may have noticed that there is a column to set most of the food's traits, but there is no column to set the food's `order` trait. This is because Pantry automatically sets the food's `order` trait so that it is equal to the line number of the food in the file, although it is left-padded with zeroes so that it will equal four digits.

Prev | Up | Next
Chapter 6. Plain text Foods files, and choosing which type of Foods file to use | Home | 6.3. Using Foods Text files