LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to use xargs within xargs ? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-use-xargs-within-xargs-4175462062/)

anindyameister 05-15-2013 04:54 AM

How to use xargs within xargs ?
 
I have a command which produces multi line output with each line consisting of two fields seperated by a '=' where the first field is a module name and the second field is the value. I have to set the value of each to something else. the command to set value syntax is like

Code:

<module name>=<value>
so I was trying xargs with -i option within an outer xargs to replace the placeholder in the command to set value location but the placeholder is being replaced with the outer placeholder value.

what i'm trying here is like this.

Code:

<command to produce multi line output> | xargs -i sh -c 'echo $0 | cut -d= -f1 | xargs -i <command to set the value> {}=<value>' '{}
'


I know it becomes easier if I redirect the output from cut to a file and then start a new xargs chain, but i am curious if there is a simpler way to do this in a single command chain.

linosaurusroot 05-15-2013 05:01 AM

I've a suspicion nested xargs might not be the best plan but from a syntax point of view "xargs -i" takes optional text to specify what the recall symbol is.
Code:

something | xargs  -i{} command thingy {}  | xargs -iAA othercommand AA


All times are GMT -5. The time now is 04:38 PM.