## Grep File

`client.retrieval.grep(RetrievalGrepParamsparams, RequestOptionsoptions?): PaginatedCursorPost<RetrievalGrepResponse>`

**post** `/api/v1/retrieval/files/grep`

Grep within a file's parsed content using a regex pattern.

### Parameters

- `params: RetrievalGrepParams`

  - `file_id: string`

    Body param: ID of the file to grep.

  - `index_id: string`

    Body param: ID of the index the file belongs to.

  - `pattern: string`

    Body param: Regex pattern to search for.

  - `organization_id?: string | null`

    Query param

  - `project_id?: string | null`

    Query param

  - `context_chars?: number | null`

    Body param: Number of characters of context to include before and after the matched pattern in the content field of the response

  - `page_size?: number | null`

    Body param: The maximum number of items to return. The service may return fewer than this value. If unspecified, a default page size will be used. The maximum value is typically 1000; values above this will be coerced to the maximum.

  - `page_token?: string | null`

    Body param: A page token, received from a previous list call. Provide this to retrieve the subsequent page.

### Returns

- `RetrievalGrepResponse`

  A single grep match within a file.

  - `content: string`

    Matched text content.

  - `end_char: number`

    End character offset of the match.

  - `start_char: number`

    Start character offset of the match.

### Example

```typescript
import LlamaCloud from '@llamaindex/llama-cloud';

const client = new LlamaCloud({
  apiKey: process.env['LLAMA_CLOUD_API_KEY'], // This is the default and can be omitted
});

// Automatically fetches more pages as needed.
for await (const retrievalGrepResponse of client.retrieval.grep({
  file_id: 'file_id',
  index_id: 'idx-abc123',
  pattern: 'revenue|profit',
})) {
  console.log(retrievalGrepResponse.content);
}
```

#### Response

```json
{
  "items": [
    {
      "content": "content",
      "end_char": 0,
      "start_char": 0
    }
  ],
  "next_page_token": "next_page_token",
  "total_size": 0
}
```
