Reputation: 7327
How in bash with sed can I check if line contains use_authtok.*sha512 and then set or add rounds=5000 ? So far I have only figured out how to add if missing using
sed 's/sha512/sha512 rounds=5000/g'
in a non-robust way.
example:
use_authtok try_first_pass sha512 remember=5
use_authtok try_first_pass sha512 remember=5 rounds=7000
desired output:
use_authtok try_first_pass sha512 remember=5 rounds=5000 # was missing here
use_authtok try_first_pass sha512 remember=5 rounds=5000 # changed from 7000
Upvotes: 0
Views: 319
Reputation: 133428
Could you please try following awk
too.
awk '
/use_authtok.*sha512/ && !sub(/rounds=[0-9]+/,"rounds=5000"){
$0=$0 " rounds=5000"
}
1
' Input_file
Upvotes: 2
Reputation: 184955
Like this using awk :
$ awk '(/use_authtok.*sha512/){$5="rounds=5000"}1' file
use_authtok try_first_pass sha512 remember=5 rounds=5000
use_authtok try_first_pass sha512 remember=5 rounds=5000
Upvotes: 2