Home Explore Blog CI



nushell

1st chunk of `commands/docs/bytes_index-of.md`
fbeaaa434d603edf0bfba8115901ba32964ecb3ecb78005600000001000008d1
---
title: bytes index-of
categories: |
  bytes
version: 0.104.0
bytes: |
  Returns start index of first occurrence of pattern in bytes, or -1 if no match.
usage: |
  Returns start index of first occurrence of pattern in bytes, or -1 if no match.
editLink: false
contributors: false
---
<!-- This file is automatically generated. Please edit the command in https://github.com/nushell/nushell instead. -->

# `bytes index-of` for [bytes](/commands/categories/bytes.md)

<div class='command-title'>Returns start index of first occurrence of pattern in bytes, or -1 if no match.</div>

## Signature

```> bytes index-of {flags} (pattern) ...rest```

## Flags

 -  `--all, -a`: returns all matched index
 -  `--end, -e`: search from the end of the binary

## Parameters

 -  `pattern`: The pattern to find index of.
 -  `...rest`: For a data structure input, find the indexes at the given cell paths.


## Input/output types:

| input  | output |
| ------ | ------ |
| binary | any    |
| record | record |
| table  | table  |
## Examples

Returns index of pattern in bytes
```nu
>  0x[33 44 55 10 01 13 44 55] | bytes index-of 0x[44 55]
1
```

Returns index of pattern, search from end
```nu
>  0x[33 44 55 10 01 13 44 55] | bytes index-of --end 0x[44 55]
6
```

Returns all matched index
```nu
>  0x[33 44 55 10 01 33 44 33 44] | bytes index-of --all 0x[33 44]
╭───┬───╮
│ 0 │ 0 │
│ 1 │ 5 │
│ 2 │ 7 │
╰───┴───╯

```

Returns all matched index, searching from end
```nu
>  0x[33 44 55 10 01 33 44 33 44] | bytes index-of --all --end 0x[33 44]
╭───┬───╮
│ 0 │ 7 │
│ 1 │ 5 │
│ 2 │ 0 │
╰───┴───╯

```

Returns index of pattern for specific column
```nu
>  [[ColA ColB ColC]; [0x[11 12 13] 0x[14 15 16] 0x[17 18 19]]] | bytes index-of 0x[11] ColA ColC
╭───┬──────┬──────────────┬──────╮
│ # │ ColA │     ColB     │ ColC │
├───┼──────┼──────────────┼──────┤
│ 0 │    0 │ [20, 21, 22] │   -1 │
╰───┴──────┴──────────────┴──────╯

```

Title: bytes index-of
Summary
The `bytes index-of` command finds the index of the first occurrence of a pattern within a byte sequence. It returns -1 if the pattern is not found. It accepts flags for finding all occurrences (`--all`), searching from the end (`--end`), and specifying cell paths in data structures.