function::text_str - Linux


Overview

text_str is a utility for converting strings to and from binary representations. It supports various encoding formats, allowing you to easily manipulate and interpret binary data.

Syntax

text_str [OPTIONS] [STRING]

Options/Flags

  • -b, –binary: Output binary representation of string.
  • -u, –unicode: Treat string as Unicode (default).
  • -a, –ascii: Treat string as ASCII.
  • -d, –decode: Decode binary data into string.
  • -f, –format=FORMAT: Encode/decode using specified format (hex, base64, urlencode, urldecode). Default is ‘hex’.

Examples

Encode a string to hex:

text_str -b Hello World

Decode hex data into string:

text_str -d 48656c6c6f20576f726c64

Encode a string to base64:

text_str -f base64 Hello World

Decode base64 data into string:

text_str -d base64 SGVsbG8gV29ybGQ=

Common Issues

  • Invalid input: Ensure input strings are in the correct encoding format. For example, binary data should be provided in hex form when using -b.

Integration

Combine with ‘xxd’ for hexadecimal manipulation:

xxd -g2 input.bin | text_str -b

Use with ‘python’ for advanced string processing:

python -c "print(text_str.text_to_str(data, 'base64'))"

Related Commands

  • xxd: Manipulate binary data in hexadecimal format.
  • iconv: Convert between character encodings.