Skip to content

Examples

Aaron Riekenberg edited this page Aug 19, 2023 · 38 revisions

Processing CSV inputs using regular expression

Suppose we have an input CSV file of http method and URL, this could be used to make parallel calls with curl. Here {method} and {url} are named regular expression capture groups:

$ cat >./test.csv <<EOL
GET,http://example.com/endpoint1
PUT,http://example.com/endpoint2
POST,http://example.com/endpoint3
EOL

$ cat test | rust-parallel -r '(?P<method>.*),(?P<url>.*)' curl -X {method} {url}

Doing computation on list of files

Suppose we have a bash function analyze_file and a list of *.txt files to analyze in current directory. This example uses --jobs 4 to control max parallel jobs, --shell to call a bash function, --progress-bar to display a graphical progress bar, and --timeout-seconds

$ analyze_file() {
  # do some expensive analysis of file $1 parameter
}

$ export -f analyze_file

$ rust-parallel --jobs 4 --shell --progress-bar --timeout-seconds $((5*60)) analyze_file ::: *.txt
Clone this wiki locally