Q:

Regarding recursive file run and replace the main content of input file

sed "s/eth0/$change/" <  ifcfg-eth0

Our file contains:
DEVICE=eth0

I want to replace the eth0 with any input I enter, every time I run the program.
To be specific, the above mentioned command does the following:
Every time I run my program, it asks to enter the value which we want in order to replace eth0. It does replace it once but the next time I run the script, it does not work because it no longer has eth0 as a pattern in the file which it can change.
sed -i will only make the changes once but i need it recursively..

A:

Use sed -i "s/^DEVICE=\(.*\)/DEVICE=$change/" ifcfg-eth0. This should replace the any pattern after DEVICE= with $change.

