Affichage des articles dont le libellé est xargs. Afficher tous les articles
Affichage des articles dont le libellé est xargs. Afficher tous les articles

mercredi 11 février 2015

awk 'system()' vs xargs

Two different syntaxes for processing a command over a list of arg.

Let's take for example, the list of PID you want to kill(all the processes matching "toto") :

ps | grep toto | awk -F' ' '{print $2}' | xargs kill -9

is equivalent to

ps | grep toto | awk -F' ' '{system("kill -9 "$2}'

note that the space at the end of the string "kill -9 " is important since the $2 will be concatenated.