Reputation: 125
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?
Upvotes: 1
Views: 52
Reputation: 9262
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.
Upvotes: 1