---
title: "Formula - csv: Extract a Column from Delimited Text"
description: The csv Formula function returns the values of one zero-based column of CSV or other delimited text, skipping header rows and comment lines. Includes syntax, parameters, and examples from body, context, and jsonPath.
---

# <i class="fal fa-function" aria-hidden="true"></i> Formula - csv

The `csv` [Formula][] function returns the values of one column of CSV or other delimited text, after skipping header rows and comment lines.

![Cut the order lines out of an Order Confirmation CSV with regex, then read their descriptions with csv, animated walkthrough (7.12)][4]  
*Animated walkthrough: the Order Confirmation of the [Order-to-Cash demo][] is a CSV file with a header, a details and a footer section. `regex('LineNumber,[^\n]*(\n\d+,[^\n]*)+', body)` cuts out the order lines with their header row. `csv(1, ',', 2, '#', regex(…))` skips that header row and returns column `2` (the third column): `Demo Widget`, `Demo Gadget` and `Demo Sprocket`.*  

## <i class="fal fa-code" aria-hidden="true"></i> Syntax

```text
csv(headerRowsToSkip, 'delimiter', columnIndex, 'commentSymbol', content)
```

### Parameters

|Parameter|Required|Description|  
|---|---|---|  
|`headerRowsToSkip`|Yes|Number of rows to skip at the top, such as a header row. A number, without quotes.|  
|`'delimiter'`|Yes|The character that separates columns, such as `','` or `';'`.|  
|`columnIndex`|Yes|The column to return, zero-based: `0` is the first column, `1` the second. A number, without quotes.|  
|`'commentSymbol'`|Yes|Lines that start with this character are ignored, such as `'#'`.|  
|`content`|Yes|The delimited text: [body][], [context][Context], or the result of another function (see [Formula language rules][]).|  

### Returns

One value per remaining row: the value in column `columnIndex`, with surrounding double quotes removed. Duplicates are collapsed. Rows that are skipped, blank, or start with the comment symbol return nothing.

## <i class="fal fa-list-ol" aria-hidden="true"></i> Examples

### Example 1: Return the second column of the message body

#### Input

```text
"face","suit","value"
"king","spades",13
"queen","spades2",12
#"jack","spades3",11
"ten","spades4",10
"nine","spades5",9
#"twenty","clown",10
"eight","spades6",8
"seven","spades7",7
```

#### Formula

```text
csv(2, ',', 1, '#', body)
```

#### Result

```text
spades2
spades4
spades5
spades6
spades7
```

![Formula csv expression returning five suit values from a CSV message body in the Test Expression tab][1]  
*The first two rows (`face` and `king`) are skipped, the two `#` lines are ignored, and column `1` (the second column) is returned.*  

### Example 2: Highest value in a context property

#### Input

The Message Context key `Ids` has this value:

```text
"face","suit","value"
"king","spades","13"
"queen","spades2","12"
#"jack","spades3","666"
"ten","spades4","10"
```

#### Formula

```text
max(csv(1, ',', 2, '#', context('Ids')))
```

#### Result

```text
13
```

![Formula max of csv on the Ids context property returning 13 in the Test Expression tab (7.12)][2]  
*`csv` returns 13, 12, and 10 from the third column; the commented `666` row is ignored, so [max][] returns `13`.*  

### Example 3: CSV embedded in a JSON field

#### Input

```json
{
    "name": "JSONFile",
    "description": "TestFile",
    "content": "\"face\",\"suit\",\"value\"\n\"jack\",\"spades3\",11\n\"ten\",\"spades4\",10\n\"nine\",\"spades5\",9\n\"eight\",\"spades6\",8\n\"seven\",\"spades7\",7"
}
```

#### Formula

```text
csv(4, ',', 1, '#', jsonPath('$.content', body))
```

#### Result

```text
spades6
spades7
```

![Formula csv over jsonPath content returning spades6 and spades7 in the Test Expression tab][3]  
*[jsonPath][] returns the CSV text of the `content` field; `csv` skips four rows (header, jack, ten, nine) and returns the second column of the rest.*  

## <i class="fal fa-circle-info" aria-hidden="true"></i> Notes

* Rows and columns count differently: `headerRowsToSkip` is a count of rows, `columnIndex` is zero-based.
* Every row after the skipped ones needs at least `columnIndex + 1` columns. One shorter row fails the whole expression, and no value is returned for the other rows either. The Test tab then says, for example: *Column index 2 is out of range on row 2, which has 1 column (the first column is 0).*
* A `headerRowsToSkip` that isn't smaller than the number of rows fails too: *The number of header rows to skip (20) is not smaller than the number of rows (12).*
* A file with several sections, such as a header, details, and footer, has rows of different widths. Cut out the section you need with [regex][] first, and run `csv` on that, as in the walkthrough above.
* For fixed-width records, use the [Flat File Fixed Width plugin][]. When one column is all you need and nothing has to be nested, the [Flat File CSV plugin][] does the job without a formula; see [Choose a plugin][].

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* <i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Add or manage Search Field][]  
* <i class="fal fa-flask" aria-hidden="true"></i> [Test Your Expression][]  
* <i class="fal fa-hard-drive" aria-hidden="true"></i> [Add or manage Log View][]  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-filter" aria-hidden="true"></i> [Extract functions][Extract Group]  
* <i class="fal fa-sitemap" aria-hidden="true"></i> [jsonPath][]  
* <i class="fal fa-key" aria-hidden="true"></i> [jsonPathKey][]  
* <i class="fal fa-text-slash" aria-hidden="true"></i> [regex][]  
* <i class="fal fa-layer-group" aria-hidden="true"></i> [regexGroup][]  
* <i class="fal fa-database" aria-hidden="true"></i> [sqllookup][]  
* <i class="fal fa-code" aria-hidden="true"></i> [xPath][]  
* <i class="fal fa-code" aria-hidden="true"></i> [xPath2][]  
* <i class="fal fa-function" aria-hidden="true"></i> [Formula][]  
* <i class="fal fa-scroll" aria-hidden="true"></i> [Formula language rules][]  
* <i class="fal fa-puzzle-piece" aria-hidden="true"></i> [Search Field Expressions][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [Flat File CSV plugin][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [Flat File Fixed Width plugin][]  

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/csv_simplebody_.png
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/MaxFromCSVContext.png
[3]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/csv_FunctionAsContent.png
[4]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/Formula_Csv.gif

[Add or manage Log View]:https://docs.nodinite.com/administration/log-management/log-views/features/add-or-manage-log-view/
[Add or manage Search Field]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/
[body]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/body/
[Choose a plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/#fa-signs-post-choose-a-plugin
[Context]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/context/
[Extract Group]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/#extract
[Flat File CSV plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/flat-file-csv/
[Flat File Fixed Width plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/flat-file-fixed-width/
[Formula]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/
[Formula language rules]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/#fa-scroll-formula-language-rules
[jsonPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/jsonpath/
[jsonPathKey]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/jsonpathkey/
[max]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/max/
[Order-to-Cash demo]:https://docs.nodinite.com/repository-model/bpms/examples/order-to-cash/generate-o2c-demo-data/
[regex]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/regex/
[regexGroup]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/regexgroup/
[Search Field Expressions]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/
[sqllookup]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/sqllookup/
[Test Your Expression]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/#test-your-expression
[xPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath/
[xPath2]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath2/