0

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?

3
  • That sounds more like something that you can build up from database commands...
    – vonbrand
    Commented Mar 24, 2013 at 2:40
  • 5
    This is what subselects are good for.. DELETE FROM (SELECT ...).
    – jordanm
    Commented Mar 24, 2013 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. Commented Mar 24, 2013 at 15:30

1 Answer 1

1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .