'Replace path in specific line number of file [closed]

i have a file which contain :

 Source defaults file; edit that file to configure this script.
 
 AUTOSTART="all"
 
 STATUSREFRESH=10
 
 OMIT_SENDSIGS=0
 
 if test -e /etc/default/openvpn ; then
 
   . /etc/default/openvpn
 
 fi

i want to change the path /etc/default/openvpn in line 5 to /mnt/data/default/openvpn the same thing about line 6. I couldn't using sed -i '5s/etc/default...' , and with awk i can't replace the result in the file.

any one have a idea please ?

Thank you.

commands tried :

var1='/etc/default/openvpn'

var2='/mnt/data/default/openvpn'

sed -i '5s/'$var'/'$var2'/' files.txt

sed -i '5s/etc/default/openvpn/mnt/data/default/openvpn/' files.txt

sed -i '5s/'/etc/default/openvpn'/'/mnt/data/default/openvpn'/g' files.txt

awk 'NR==5 { sub("/etc/default/openvpn", "/etc/default/openvpn", $0); print }' files.txt

with awk, i can't save changes in the file



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source