0

This question already has an answer here:

I am not sure whether the below statement can be done placing & inside $() so that each time & is replaced by 1,2,3,4 and 1 is added to it.

echo 1 2 3 4 | tr ' ' '\n' | sed "s/.*/$(echo expr 1 + &)/"

The above statement doesn't work

i get the output :

expr 1 +
expr 1 +
expr 1 +
expr 1 +

marked as duplicate by terdon, slm, jasonwryan, Anthon, manatwork Oct 10 '13 at 8:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You might, perhaps, with considerable effort and command line gymnastics manage to do so, but if you need to do this you are almost certainly doing something wrong. What is the actual problem you are trying to solve? – terdon Oct 10 '13 at 0:28
1

If you don't need to use sed for this, here are a few other options:

$ echo 1 2 3 4 | tr ' ' '\n' | while read f; do let f+=1; echo $f; done
2
3
4
5
$ echo 1 2 3 4 | tr ' ' '\n' | awk '{print $1+1}'
2
3
4
5
$ echo 1 2 3 4 | tr ' ' '\n' | perl -lne '$i=$_+1; print $i'
2
3
4
5

sed is a stream editor, it is not supposed to do mathematical expressions.

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