Skip to main content

Embed python expressions in bash

Project description

pyil - PYthon InLine

Simple in Python, but hard in BASH? pyil is here to help!

A small utility to use Python expressions in bash scripts

badge

Installation

$ pip3 install pyil-bin

Examples

Print squares

$ echo nums.txt
1
2
3
$ cat nums.txt | pyil "int(i) ** 2"
1
4
9

pyil evaluates the expression using Python, by default once per each line. The line is provided in i variable to the expression evaluation context (without the trailing \n)

Print only even numbers

$ echo nums.txt
1
2
3
$ cat nums.txt | pyil -g "int(i) % 2 == 0"
2

The -g (--grep) option enables line filtering mode - the expression is not printed, but used to determine if the line should be printed

Usage

usage: pyil [-h] [-l | -g | -t | -n] [-i] [-j] E

Shortcut for using Python for line processing

positional arguments:
  E               expression to evaluate

optional arguments:
  -h, --help      show this help message and exit
  -l, --lines     Evaluate expression once, with the `lines` generator
  -g, --grep      Instead of printing the value use it for filtering lines
  -t, --truish    Print only values where bool(val) == True
  -n, --none      Print only values where val != None
  -i, --iterable  Threat resulting value as iterable of separate lines. Usefull with --lines, ignored with --grep
  -j, --json      Print value using json.dump(). Together with --iterable results in NDJSON, ignored with --grep

More examples

TBD

Please report all bugs to GitLab issues

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyil-bin-0.1.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

pyil_bin-0.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file pyil-bin-0.1.tar.gz.

File metadata

  • Download URL: pyil-bin-0.1.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for pyil-bin-0.1.tar.gz
Algorithm Hash digest
SHA256 3bb048c098c199deeda0f7e182064349e159289146a32005afd461097fb2baaa
MD5 e212a226e9090f57380ea5bea227cf95
BLAKE2b-256 3639f79dd105518ebd974794fe80212e7e625840a83672b96cf5b95b9cc30fac

See more details on using hashes here.

File details

Details for the file pyil_bin-0.1-py3-none-any.whl.

File metadata

  • Download URL: pyil_bin-0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for pyil_bin-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0582781b23c06bb65251e5a6586e333e1c3ca28e42bacffbfa28e886ba447e81
MD5 289b8a4fa95417da3f58832cafe85cc1
BLAKE2b-256 668a8959af0b6e5be538c96cdcc5d05c9adaa48fa3f9fbc7f088d8470a3c9150

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page