Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have a file named variables.f90 , having many lines defining different variables, as follows ::

integer::n_monomer=6800
real*8::rx=5.0d0
#... randomly integer and real numbers defined
real*8::mu_nano=8.0d0
.......
......

and I dont know what will be the value of mu_nano, it can be any real number. Now I want to modify the above statement such that, its value is incremented by 1 using bash script as follows ::

real*8::mu_nano=9.0d0
share|improve this question

2 Answers 2

To edit in place, I'd use perl:

perl -i.bak -pe 's/(?<=mu_nano=)([\d.]+)/ sprintf "%.1f", $1+1 /e' variables.f90
share|improve this answer
    
Thanks you very much. –  mubeena Jan 7 at 6:58

This looks like fortran code, and it is not the greatest idea ever to parse higher language source code, but anyway... with awk:

awk -F'[=.]' '/nano/{$2++; print $1"="$2"."$3; next}1'

This assumes that variable is always given with a dot. It takes only integer part of it (between = and .), increase by 1, and prints everything back.

share|improve this answer
    
ya, it works. Thanks. –  mubeena Jan 7 at 2:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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