Linux – Read the properties file in Linux

Read the properties file in Linux… here is a solution to the problem.

Read the properties file in Linux

I want to be able to read the properties file in Linux to check if some properties exist. If the properties I’m looking for exist but they don’t match the value I’m looking for, I want to override those respective properties. If they don’t exist, then I want to write them to a file.

Any linux guru can help me with this.

Thanks in advance!

The key name can also be in the form pre1.pre2.pre3
So like
pre1.pre2.pre3 = value

Here is the properties file

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.all.disable_ipv6 = 1
kernel.sysrq = 0
net.ipv4.ip_forward = 0
net.ipv4.tcp_syncookies = 1
net.ipv6.conf.all.forwarding = 0
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_keepalive_intvl = 5
net.ipv4.tcp_keepalive_probes = 5

I want to basically change all the settings for tcp.


Here are some steps you might find useful for your script:

  • Does exist in

if grep ; Then Echo discovered; otherwise echo cannot be found; fi

-> if test the result of grep

  • Replace the attribute with the new value

cat | sed '/\ = new value'

-> sed changes the entire line with the c command

Looks like you only need the last command 🙂

ps: I love these “avoid bash” discussions 🙂

Related Problems and Solutions