0

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?

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

1

Here is the solution:

sed -rni 's/^(.*\bunlock_time\b=)([0-9]+)(.*)$/\1<PARAM_VALUE>\3/p' <CONFIG_FILE>

1 Comment

Thank you! This is a good solution. The only thing is that replace everything in the file and leave only the line that matches the pattern

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.