Skip to content

Instantly share code, notes, and snippets.

@livelace
Created March 1, 2022 01:29
Show Gist options
  • Save livelace/0e1f01f01ffa9553e3223dd680c57802 to your computer and use it in GitHub Desktop.
Save livelace/0e1f01f01ffa9553e3223dd680c57802 to your computer and use it in GitHub Desktop.
Run shell function in parallel over file lines
#!/usr/bin/env bash
FILE="/tmp/file.txt"
PROC=3
echo -e "aaa bbb ccc\nddd eee fff" > "$FILE"
function do_it() {
echo "---"
printf "$1 $2 $3\n"
}
export -f do_it
mapfile -t "LINES" <"$FILE"
parallel -j "$PROC" ::: do_it ::: "${LINES[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment