Change values in .conf file with a script

This is my first time posting here...so be gentle.

Suppose I have a test.conf file that contains a value such as a IP. I would like to be able to use the Dialog Utility in Linux to allow me to enter the new IP in a Dialog form...and the results get saved into the test.conf file in the place where the IP is stored.

The only way I can think to do this is to have that IP as a variable...and have it read from a file stored somewhere. But I am not sure that's the best way.

BTW this is on a Linux based system (Raspberry Pi)

I have played with the dialog utility before...but not to write to a file....nor to substitute a value

Examples would be GREAT

It sounds like a reasonable approach to me. Maybe this example might help:

$ cat test.conf
ip=192.168.0.3
os=linux
CONFIG_FILE=/tmp/test.conf
old_ip=`grep "^ip=" "$CONFIG_FILE" | sed "s/ip=//"`

# run dialog commands
# dialog displays old ip address
# dialog gets new ip address into "new_ip" variable
# dialog validates new ip address
# dialog verifies you want to change the ip address.

sed "s/^ip=.*/ip=$new_ip/" "$CONFIG_FILE" > /tmp/temp.x
mv /tmp/temp.x "$CONFIG_FILE"
1 Like

Works great! I need to polish up my dialog boxes, but so far it is doing what I want!

Thanks again :b:

I'm glad it's working. Also, I did not know about dialog before. That looks like a really great way to write interfaces. Thank you for posting. :slight_smile:

grep "^ip=" "$CONFIG_FILE" | sed "s/^ip=//"

can be simplified

<"$CONFIG_FILE" sed -n "s/^ip=//p"