Skip to content
This repository has been archived by the owner on Jun 1, 2021. It is now read-only.

Commit

Permalink
Simplified running a command on multiple datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
joelpurra committed Aug 25, 2014
1 parent d61f717 commit c760561
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/util/dataset-query.sh
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -e

# Execute parallel commands per folder, collecting the output on stout.
#
# USAGE
# "$0" <folder(s)> -- <command(s)>
# "$0" "folder0" "folder1" "folderN" -- mycommand --option --whatever '{}'
# "$0" "folder0" "folder1" "folderN" -- echo '"\"This data from the pipe\""' '|' jq --arg folder '{}' --arg pwd '"$PWD"' "'{ folder: \$path, pwd: \$pwd, pipe: . }'"
#
# Separate folder(s) and command(s) with "--".
# Use '{}' in the command to get the folder as input.
# The entire command doesn't have to be a string - everything after '--' will be executed.
# Quote strings used in the command twice; '"string with spaces"'.
# Separate shell commands like semicolon, ampersands and pipe need to be quoted.

folders=()

while [[ "$1" != "--" ]]; do
folders+=("$1")

shift
done

shift

command="$@"

parallel --group -N 1 cd "--" "{}" "&&" "$command" ::: "${folders[@]}"

0 comments on commit c760561

Please sign in to comment.