I have to replace the numeric values contained into a rhel configuration file through a bash script:
auth required pam_tally2.so onerr=fail deny=5 even_deny_root unlock_time=600 root_unlock_time=600
As long as these values are not the same, I'm unable to match a pattern. How can I find and replace (for example) unlock_time=600 with unlock_time=1000?
CodePudding user response:
Using sed
$ sed 's/\(\<unlock_time=\)[^ ]*/\11000/' input_file
auth required pam_tally2.so onerr=fail deny=5 even_deny_root unlock_time=1000 root_unlock_time=600
CodePudding user response:
Here is the solution:
sed -rni 's/^(.*\bunlock_time\b=)([0-9] )(.*)$/\1<PARAM_VALUE>\3/p' <CONFIG_FILE>