Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can someone provide an example for the command xargs? I want to do a mysql query to return the ID field of a column then feed that result into xargs into another command say mysql query delete. How can this be done?

share|improve this question
That sounds more like something that you can build up from database commands... – vonbrand Mar 24 '13 at 2:40
This is what subselects are good for.. DELETE FROM (SELECT ...). – jordanm Mar 24 '13 at 3:52
There's an example in the xargs man page. What are you trying to do? I don't understand what difficulting you're running against. You should at least write down a sample mysql command and its output, and what you want to do with it. – Gilles Mar 24 '13 at 15:30
up vote 1 down vote accepted

xargs deals badly with special chars (" ' space), so I will give you an example using GNU Parallel:

sql -n mysql://user:pass@host/my_db "select data from my_table" | parallel -q sql mysql://user:pass@host/my_db "delete from my_table where data='{}'"

It takes literally 10 seconds to install GNU Parallel (which includes GNU SQL):

wget pi.dk/3 -qO - | sh -x

Watch the intro videos to learn more: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.