aaronriekenberg / rust-parallel

Fast command line app in rust/tokio to run commands in parallel. Similar interface to GNU parallel or xargs plus useful features. Listed in Awesome Rust utilities.
MIT License
146 stars 7 forks source link

Add regular expression matching on input #5

Closed fallalex closed 1 year ago

fallalex commented 1 year ago

I would love to see the main feature of lotabout/rargs added to this tool. I could benefit from a combination of these two xarg alternatives. Avoiding output interleaving, improved performance, and regex groups from input passed to the target command would be fantastic for some powerful oneliners!

aaronriekenberg commented 1 year ago

Thanks for the suggestion @fallalex

I will look into this.

aaronriekenberg commented 1 year ago

I like the idea of adding support for something like the -p mode of rargs, so commands of this form could work and run in parallel:

ls *.bak | rargs -p '(.*)\.bak' mv {0} {1}

cat download-list.csv | rargs -p '(?P<url>.*),(?P<filename>.*)' wget {url} -O {filename}

I think if -p is specified:

  1. The regular expression pattern would be applied to each input line/command
  2. Capture groups like {0} {url} etc would be replaced in each line before the command is run.

Will start working on this as I have time.

aaronriekenberg commented 1 year ago

Working on this in regex branch

aaronriekenberg commented 1 year ago

Released in version 1.7.1 today.

Add new -r / --regex option for regular expression capture group processing.

See the demos for examples: https://github.com/aaronriekenberg/rust-parallel/wiki/Demos#regular-expression

fallalex commented 1 year ago

Thanks for adding this. Super excited for this feature! I am going to try replacing rargs and xargs with rust-parallel in my work flow!

jyrimatti commented 12 months ago

Hi, thanks for the feature! ...but with the command having any other use of curly braces breaks completely, for example:

> echo 'input' | rust-parallel -r '.*' echo 'as json: {"id":123, "input":{0}}'
as json: }

I guess a good-enough fix would be to only consider references of format {[a-zA-Z0-9_]+} (or something similar) and nothing else?

aaronriekenberg commented 12 months ago

You are correct @jyrimatti ! Thanks for reporting this.

I created a new issue and will work on fixing this: https://github.com/aaronriekenberg/rust-parallel/issues/9