Is it possible to grep the result of a command spawned by xargs?
As an example I am trying the following command
findbranch prj-xyz -latest|sed 's/^\(.*\/.*\)@@.*$/\1/'|xargs -I {} cleartool lsh {}|grep -m 1 'user'
but seems like grep is executing on the entire result set returned by findbranch, rather individual results of lsh
As an example what I want from above is, for every file returned by findbranch and sed combined I would like to find that version which was last modified by a certain user.
Note If in case it is of a concern, findbranch is an internal utility.
How about this approach?
.... | xargs -I {} bash -c "cleartool lsh {}|grep -m 1 'user'"
I guess, this answer is self explanatory for you...
Why not use a two phase command? something like
findbranch prj-xyz -latest|sed 's/^\(.*\/.*\)@@.*$/\1/' > /tmp/x ; for x in `cat /tmp/x`; do echo $x; done
Once you see $x
is the input you need for xargs
you can further manipulate it
If you have GNU Parallel this ought to work:
findbranch prj-xyz -latest|sed 's/^\(.*\/.*\)@@.*$/\1/'|parallel cleartool lsh {}'|'grep -m 1 'user'
It will still spawn multiple shells, but at least you can use more CPUs to process it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.