1

I have in my file a line of this kind

    integer, parameter ::  L = 2   !Size of the system

Where the number 2 can be any integer number. I want to find this line using sed and replace the value of the number with another one.

I tried:

$ L=5
$ sed -i '/L = /c\integer, parameter ::  L = $L   !Size of the system' moduleselfcons.f90

but in my modified file I have at the end:

integer, parameter ::  L = $   !Size of the system

and not:

integer, parameter ::  L = 5   !Size of the system

What is the problem?

chaos
  • 8,162
  • 3
  • 33
  • 40
user3368447
  • 125
  • 3
  • 10
  • possible duplicate of [Expansion of variable inside single quotes in a command in bash shell script](http://stackoverflow.com/questions/13799789/expansion-of-variable-inside-single-quotes-in-a-command-in-bash-shell-script) – Etan Reisner Oct 27 '14 at 15:09

1 Answers1

1

You should use double quotes (") instead of single quotes (').

But I think you can shorten the expression:

L=5
sed "s/L = [0-9]*/L = $L/" file

If it is your desired output add the -i flag for in-place editing.

chaos
  • 8,162
  • 3
  • 33
  • 40