Skip to content

Instantly share code, notes, and snippets.

@tarekeldeeb
Created August 13, 2018 12:01
Show Gist options
  • Save tarekeldeeb/b8ba7d014c038c76430a3e34289ca757 to your computer and use it in GitHub Desktop.
Save tarekeldeeb/b8ba7d014c038c76430a3e34289ca757 to your computer and use it in GitHub Desktop.
Run a bash script on parallel N-defined processes
#!/bin/bash
#Write your function here, will pass arguments: $1, $2, ..
getalphabet() {
> "$1"_alphabet.txt awk 'BEGIN{FS=""} {for(i=1;i<=NF;i++){chars[$(i)]=$(i);}} END{for(c in chars){print c;} }' $1 | sort >/dev/null
}
N=8;i=0
for f in `ls ar_*`; do
((i=i%N)); ((i++==0)) && wait
getalphabet $f &
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment