W3cubDocs

/Nushell

bytes index-of for bytes

Returns start index of first occurrence of pattern in bytes, or -1 if no match.

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 int
record record
table table

Examples

Returns index of pattern in bytes

>0x[3344551001134455] |bytes index-of0x[4455]
1

Returns index of pattern, search from end

>0x[3344551001134455] |bytes index-of-e0x[4455]
6

Returns all matched index

>0x[334455100133443344] |bytes index-of-a0x[3344]
╭───┬───╮
00
15
27
╰───┴───╯

Returns all matched index, searching from end

>0x[334455100133443344] |bytes index-of-a-e0x[3344]
╭───┬───╮
07
15
20
╰───┴───╯

Returns index of pattern for specific column

>  [[ColAColBColC]; [0x[111213] 0x[141516] 0x[171819]]] |bytes index-of0x[11] ColAColC
╭───┬──────┬──────────────┬──────╮
# │ ColA │     ColB     │ ColC │
├───┼──────┼──────────────┼──────┤
00 [20, 21, 22] -1
╰───┴──────┴──────────────┴──────╯

Copyright © 2019–2023 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/bytes_index-of.html