Artificial intelligent assistant

sed + un-comment parameter and change value in file I want to uncomment the wal_level parameter and change the value from minimal to archive how to perform this action by sed / perl one-liner ? $ grep wal_level /var/lib/pgsql/data/postgresql.conf #wal_level = minimal # minimal, archive, or hot_standby expected results: wal_level = archive # minimal, archive, or hot_standby Note that `wal_level` could be couple of spaces from the "#". For example: # wal_level = minimal or # wal_level = minimal etc.

perl -pi.BAK -aF'/(\h*[#=]\h*)/,$_,4' -le '
$F[4] = "archive";
$_ = join $,, @F[2..$#F] if /^\h*#\h*wal_level\h*=/;
' /var/lib/pgsql/data/postgresql.conf


The line is split into fields `@F` and the delimiters are included as well. The parameter 4 in the field split option `-F` will constrain the number of fields to that. The fields from 3rd onwards are joined together using empty space, which is the default value of the `OFS = $,`

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy e65cc8488da29a4acb6ab404e986bf58