Decrement one from 3rd Column

Hi,

I need a script that will subtract 1 from the third column of the line beginning with %, leaving all other values the same. So 158 should be 157, 308 should be 307, 458 should be 457.

Before:
#    30109    xyz abc Data
%    30109    158    5    8    2
000023f
01f4145
#    30109    xyz abc Data
%    30109    308    5    8    2
003a300
01f4145
#    30109    xyz abc Data
%    30109    458    5    8    2
39c3b92
01f4145

After:

Before:
#    30109    xyz abc Data
%    30109    157    5    8    2
000023f
01f4145
#    30109    xyz abc Data
%    30109    307    5    8    2
003a300
01f4145
#    30109    xyz abc Data
%    30109    457    5    8    2
39c3b92
01f4145

Thanks for your help,
morrbie

awk '/^%/ { $3-=1;} {print $0}'  oldfile > newfile

Does the below suffice your requirement ?

awk '{if ($1 ~ /^%/){$3-=1;print $0}else print $0}' input_file

Yes both of the above answers work.

I also figured out a solution after doing a little research on awk scripting:

awk -v val="1" '$1=="'%'" {for(i=3;i<=3;i++) $i=$i-val}1' infile>outfile

Thanks you for a quick response and for all your help!