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

Re: how to refrain only use certain number of processors



On Tue, Jan 31, 2012 at 12:05 AM, Jochen Spieker <ml@well-adjusted.de> wrote:
> 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,

Yes. the ultimate goal is:

for i in {0..108}
do
cat A_$i.txt B_$i.txt C_$i.txt -o ABC_$i.txt  (output as ABC_$i.txt)
done

but here I wish to use only 8 processors at most, total is 16.
the administrator of the cluster asked me not to use whole, cause
someone else needs SMP server.

each cat in my situations last 5~10 mins,
> 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

I used to do it in a very clumsy way like seq 0 3 | sed 's/^.*$/A$/g'
| sed 's/^.*$/&.jpeg/g'. Thanks, it's smart.

>
> 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>


Reply to: