0

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 +
munish
  • 7,825
  • 24
  • 71
  • 97
  • 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](http://meta.stackexchange.com/q/66377/203101) you are trying to solve? – terdon Oct 10 '13 at 00:28

1 Answers1

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.

terdon
  • 234,489
  • 66
  • 447
  • 667