[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: how to refrain only use certain number of processors



lina:
> 
> well, a question,
> 
> $ seq 0 3 | xargs --verbose echo A
> echo A 0 1 2 3
> A 0 1 2 3
> 
> How can I make the output as:
> 
> A0 A1 A2 A3

Your problem in this case is that xargs adds whitespace before adding
arguments. What you can do is to modify seq's output before xargs sees
it:

$ seq 0 3 | sed -e 's/^/A/'
A0
A1
A2
A3

Which leads to:

$ seq 0 3 | sed -e 's/^/A/' | xargs --verbose echo
echo A0 A1 A2 A3
A0 A1 A2 A3

> P.S Very good explaination.

Thanks!

BTW: when requesting these things it is often better to ask for the real
thing you want to achieve. Synthetic examples like these most often
don't cover all cases or leave out important information. For example,
if "A0" should actually be a filename, your next question might be how
to get from "A0" to "A0.jpeg":

$ seq 0 3 | sed -e 's/^/A/' -e 's/$/.jpeg/'
A0.jpeg
A1.jpeg
A2.jpeg
A3.jpeg

The two sed expressions perform search & replace at the beginning (^)
and at the end ($) of the line-.

J.
-- 
My memories gild my life with rare transcendance.
[Agree]   [Disagree]
                 <http://www.slowlydownward.com/NODATA/data_enter2.html>

Attachment: signature.asc
Description: Digital signature


Reply to: