LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-15-2013, 05:54 AM   #1
anindyameister
Member
 
Registered: Oct 2012
Posts: 47

Rep: Reputation: Disabled
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.
 
Old 05-15-2013, 06:01 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 979
Blog Entries: 2

Rep: Reputation: 235Reputation: 235Reputation: 235
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
xargs: unmatched single quote; by default quotes are special to xargs unless you use Raakh5 Linux - Newbie 7 05-21-2014 08:26 PM
Using xargs drpartha Linux - Software 4 10-27-2012 12:32 PM
Using xargs SBN Linux - General 2 04-07-2008 08:44 PM
`wc`, `xargs` h/w Programming 11 09-30-2007 05:22 PM
xargs yawe_frek Linux - Software 1 04-15-2007 05:26 PM


All times are GMT -5. The time now is 06:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration