Use xargs with functions

Example:

—————————-
worker () {
echo $1
}

export -f worker # This is important

cat inputList.txt | xargs -L 1 -I {} -P 4 bash -c “worker {}”
# Use bash -c “CommandToExecute”

—————————-

This trick can also be used with the find command.
find . -name ‘*.txt’ -exec bash -c “worker {}” \;
# Do not forget the “\;” termination for the -exec option of find.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s