How to replace

Here is my file content

age=12
age=34
age=54
age=23
Hello world. This is the age result I am getting.
To day date is 23-02-2010.

From the above content I have to replace all the values after 'age=*' to age=24.

How to do it.

Welcome to the forum. Perhaps this will do for your application:

sed 's/=.*/=24/' infile

More strict would be:

sed 's/^age=.*/age=24/' infile

even more strict:

sed 's/^age=[0-9]*$/age=24/' infile

awk:

awk -F= '$1=="age"&&NF==2{$2=24}1' infile
1 Like