Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

for exmaple, using the command

cat foo.txt | xargs -I{} -n 1 -P 1 sh -c "echo {} | echo"

The foo.txt contains two lines


The above command print nothing.

share|improve this question

closed as unclear what you're asking by Dennis Williamson, cole, Dennis Kaarsemaker, Jenny D, freiheit Dec 24 '13 at 22:55

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

cat foo.txt | xargs -J % -n 1 sh -c "echo % |" 

Tricky part is that xargs performs implicit subshell invocation. Here sh invoked explicitly and pipe not becomes the part of parent conveyor

share|improve this answer
Thanks, I have updated my question to provide a more concret example. but it does not work as you suggested.. – Ryan Dec 24 '13 at 9:13
echo cant read from stdin, so piping to it has no sense. compare this: cat | wc -l and cat | xargs -J % -n 1 sh -c "echo % | wc -l" – Kondybas Dec 24 '13 at 9:50

If you want to process all the lines of foo.txt you will have to use a loop. Use & to put the process to background

while read line; do
   echo $line | &
done < foo.txt

If your input contain spaces temporarily set the internal field separator to the newline

# save the field separator

# new field separator, the end of line 

for line in $(cat foo.txt) ; do
   echo $line | &

# restore default field separator  
share|improve this answer
No-no, I'm stuck with it too. TS want to split file into seperate lines and feed them into script independently – Kondybas Dec 24 '13 at 7:19
I need to use xargs to parallel the process.. – Ryan Dec 24 '13 at 7:21
OK :-) I just looked up the options of xargs the OP used. – Matteo Dec 24 '13 at 7:25

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