how to change a number in a file with sed?

Hello,

I have a file which contains some line as follows,

9.9 TEMP
9.9 MUCOEFF
0.0 EPSILON

And I want to increase this MUCOEFF by 0.2 as

9.9 TEMP
10.1 MUCOEFF
0.0 EPSILON

I browsed this forum for a bit and find some tips using sed, awk,..
But still do not know to change this number infront of MUCOEFF.
Note that space between 9.9 and MUCOEFF changes from file to file,
but this 9.9 is always comes first in line.

Any tips will be great help !
Specially complete method using sed will be really nice for me.

Try awk:

awk '/MUCOEFF/{$1+=.2}1' file

Thanks danmero, it worked in command line.
But it do not work in makefile.
I stored this in makefile for frequent use, but $1 do not work.
Is there any solution?

To understand your situation you have to post your script.

Did you mean passing env vars that contain values to be incremented ?

awk -v var=0.2 '/MUCOEFF/ { $1+=var}1' b

I made makefile as follows,

test:
awk '/MUCOEFF/{$1+=0.6}1' filename > filename

and when I type "make test", I get

awk: /MUCOEFF/{+=0.6}1
awk: ^ syntax error
make: *** [test] Error 1

It seems that "$1" do not recognized.

The simpliest way is to put your awk script into a seperate file and call this script using the awk -f option i.e.

file1:
        @echo "Calling awk -f awkfile ...."
        awk -f awkfile file > file1

where awkfile contains

/MUCOEFF/ {$1+=0.6}1

fpmurphy//
But it is just part of the full script which is long and depend on many variables.
So I want to put this full script in file and use it conveniently.