m2-farzan / px

A simple python-based CLI utility that is not *awk*ward

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

usage: px [-h] [-L] [--pre FUNC] [--post FUNC] [-i MODULE] [--stack] [-x X]
          expr [file ...]

My Python version of `awk`

positional arguments:
  expr          python expression to evaluate
  file          input file(s) (use `-` for stdin)

optional arguments:
  -h, --help    show this help message and exit
  -L, --linear  linear mode
  --pre FUNC    preprocessing applied to cells
  --post FUNC   postprocessing applied to result object
  -i MODULE     from MODULE import * (separate multiple modules with `,`)
  --stack       stack all files into one
  -x CMD        execute arbitary python command before exit
  --no-none     don't print None items in results
  --bo          [binary output] keep output in python object format. (useful for piping to another px process.)
  --bi          [binary input] parse input in python object format. (useful for piping from another px process.)

examples:
  px 3+4
  px -L x+y a.txt b.txt
  px -L "f'name:\t{x}'" <(ls)
  px -i math 'sin(pi/3)'
  px --pre=int sum(x) series1.txt
  px -L -i json --post dumps "{'name': x[4:].strip(), 'size': x[:4].strip()}" <(ls *.pdf -sh)
  px --pre="lambda a: a**2+1" "[X/Y for X,Y in zip(x,y)]" <(px [4,3,3]) <(px [1,1,3])
  px -i numpy,matplotlib.pyplot "plot([1,2],[4,2])" -x "show()"
    
installation (local):
  [Assuming ~/.local/bin is in PATH.]
  wget -O ~/.local/bin/px https://raw.githubusercontent.com/m2-farzan/px/main/px
  chmod +x ~/.local/bin/px

installation (global):
  [Assuming /usr/local/bin is in PATH.]
  sudo wget -O /usr/local/bin/px https://raw.githubusercontent.com/m2-farzan/px/main/px
  sudo chmod +x /usr/local/bin/px

tutorial:
  https://nbviewer.jupyter.org/github/m2-farzan/px/blob/main/tutorial.ipynb

About

A simple python-based CLI utility that is not *awk*ward

License:MIT License


Languages

Language:Python 100.0%