Issue
in /etc/barman.conf
configuration file
we have the following line
retention_policy = RECOVERY WINDOW OF 7 days
in our bash script we want to add sed command or maybe Perl one liners , that will change the integer value between the words "OF" and "days"
number 7 in above example - could be any integer number and should be replace according to new value - $NUM_OF_DAY
we tries with following option , that replaced the value after “=” separator but without success
NUM_OF_DAYS=23
sed '/retention_policy/!b; n; s/RECOVERY WINDOW OF [0-9]+ days/RECOVERY WINDOW OF $NUM_OF_DAYS days/g' /etc/barman.conf
or maybe the best option is completely delete the words/value after “=” separator and re-set the new line - RECOVERY WINDOW OF $NUM_OF_DAY days
Solution
Using sed
$ num_of_days=23
$ sed -E "/^(retention_policy[^[:digit:]]*)[[:digit:]]+/s//\1$num_of_days/" /etc/barman.conf
retention_policy = RECOVERY WINDOW OF 23 days
Answered By - HatLess Answer Checked By - David Goodson (WPSolving Volunteer)