Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Consider the output:

% { echo one; echo two; echo three; } | xargs -I{} -L1 echo test-{} 
test-{} one
test-{} two
test-{} three

Why doesn't {} get substituted as per the manual page (and my memory, too)?

How to change the command line to get test-one, test-two, test-three lines as output?

share|improve this question
add comment

3 Answers

up vote 8 down vote accepted

Remove the -L 1; it is implied by -I (as the man page says), but it would override it when specified afterwards.

share|improve this answer
add comment

If you have GNU Parallel http://www.gnu.org/software/parallel/ installed you can do this:

{ echo one; echo two; echo three; } | parallel echo test-{}

You can install GNU Parallel simply by:

wget http://git.savannah.gnu.org/cgit/parallel.git/plain/src/parallel
chmod 755 parallel
cp parallel sem

Watch the intro videos for GNU Parallel to learn more: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

share|improve this answer
    
+1, this is a nice script. –  ulidtko May 9 '12 at 22:35
add comment

It works without "-L1", because it is implicitly set.

{ echo one; echo two; echo three; } | xargs -I{} echo test-{}
test-one
test-two
test-three
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.