Yes I tried, but below is the result, which is not exact result.
$ActionExecOnlyWhenPreviousIsSuspended on
command-
sed 's/^$ActionExecOnlyWhenPreviousIsSuspended/#$ActionExecOnlyWhenPreviousIsSuspended/' /etc/rsyslog.conf
Result- #$ActionExecOnlyWhenPreviousIsSuspended on - its done, and fine
&@@10.10.10.10
Command
sed 's/^&@@10.10.10.10/#&@@10.10.10.10/' /etc/rsyslog.conf
Result- #&@@10.10.10.10@@10.10.10.10 - its replacing "#", but its replacing wrong
& /var/log/localbuffer
Command- sed 's/^& /var/log/localbuffer/#& /var/log/localbuffer/' /etc/rsyslog.conf
Result- sed: -e expression #1, char 11: unknown option to `s'
$ActionExecOnlyWhenPreviousIsSuspended off
Command- sed 's/^$ActionExecOnlyWhenPreviousIsSuspended/#$ActionExecOnlyWhenPreviousIsSuspended/' /etc/rsyslog.conf
Result- #$ActionExecOnlyWhenPreviousIsSuspended off - fine its good
Only problem in 2 & 3 .
so, looking help on this only.
The & is special in sed in the replacement string. This is avoided now.
But:
The $ is special in a RE (the search string) if it's the last character.
The . is special in a RE: it means any character (not only a . character).
Better use the shell:
while IFS= read -r line
do
case $line in
# add a # character
( '&@@10.10.10.10'* ) line=#${line};;
# remove a # character
# ( '#&@@10.10.10.10'* ) line=${line#\#};;
esac
printf "%s\n" "$line"
done < /etc/rsyslog.conf
Within a 'string' the remaining problem character is ' . The quick workaround is '\'' .