back

by elesiuta·3y ago·view on hn ↗
pyxargs [1]

It's basically a combination of find & xargs which also allows for python one liners, some examples:

create a JSON mapping of /etc/hosts

  cat /etc/hosts | pyxargs -d \n -s "\s+" --im json --pre "d={}" --post "print(dumps(d))" --py "d['{0}'] = '{1}'"
unmount all usermounts

  pyxargs --py "print('{}') if os.path.ismount('{}') else ''" | pyxargs fusermount -u {}
My primary use case was using this with ffmpeg due to the encoding problem with xargs [2].

It can also run commands in parallel using a terminal multiplexer so outputs don't get mixed up or if they require user input.

[1] https://github.com/elesiuta/pyxargs

[2] https://en.wikipedia.org/wiki/Xargs#Encoding_problem