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?

  • That sounds more like something that you can build up from database commands... – vonbrand Mar 24 '13 at 2:40
  • 5
    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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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