0

pretty silly question.

So basically I have a file like this

0 1 2 3 4 5 ... 1321

What I want is to add an integer to every element of the string, so for instance I want to add 1 so that it will become:

1 2 3 4 5 6 ... 1322

Thanks for the answers.

Mahad

  • yep i was trying with awk something like has been suggested: awk '{s+=$1} END {print s}' myinputfile but the result is 0 – user2710445 Mar 26 '15 at 11:32

1 Answers1

0

This line would make a line by line list

echo "1 2 3 4 5 6" | sed "s/ /\n/g" | awk '{print $1+1}'

and using How can I replace a newline (\n) using sed? You can do

echo "1 2 3 4 5 6" | sed "s/ /\n/g" | awk '{print $1+1}' | sed ':a;N;$!ba;s/\n/ /g'

And, replace your my echo ... with cat yourfile

cat yourfile | sed "s/ /\n/g" | awk '{print $1+1}' | sed ':a;N;$!ba;s/\n/ /g'

Community
  • 1
  • 1
jaromrax
  • 274
  • 1
  • 12