# Prefix

```
yq p <yaml_file> <path>
```

See docs for [path expression](/yq/v3.x/usage/path-expressions.md) for more details.

## Prefix a document

Given a data1.yaml file of:

```yaml
a:
  b: [1, 2]
```

then

```bash
yq p data1.yaml c.d
```

will output:

```yaml
c:
  d:
    a:
      b: [1, 2]
```

## Updating files in-place

```bash
yq p -i data1.yaml c
```

will update the data1.yaml file so that the path 'c' prefixes the document.

## Multiple Documents

### Prefix a single document

Given a data1.yaml file of:

```yaml
something: else
---
a: simple
b: cat
```

then

```bash
yq p -d1 data1.yaml c
```

will output:

```yaml
something: else
---
c:
  a: simple
  b: cat
```

### Prefix all documents

Given a data1.yaml file of:

```yaml
something: else
---
a: simple
b: cat
```

then

```bash
yq p -d'*' data1.yaml c
```

will output:

```yaml
c:
  something: else
---
c:
  a: simple
  b: cat
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mikefarah.gitbook.io/yq/v3.x/commands/prefix.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
