Issue
I need to deactivate certain lines in a file that starts with *
by putting #
at the front of the line.
At first, sed -i 's/*/#*/g' tmp.conf
seems to work. But it adds #
as many as I run the command.
user@host:/etc/security/limits.d:$ cat tmp.conf
#* soft nproc 4096
root soft nproc unlimited
user@host:/etc/security/limits.d:$ sudo sed -i 's/*/#*/g' tmp.conf
user@host:/etc/security/limits.d:$ cat tmp.conf
##* soft nproc 4096
root soft nproc unlimited
So it has to ignore when the line starts with #
, otherwise put #
at the front.
I searched to come up with sed -i 's/^(?!#)\*/#*/g' tmp.conf
, which doesn't work.
What regex should I use to find *
, not #*
?
Or is there any other way to do this other than using sed
?
Solution
Maybe with this?
sed 's/^\*/#&/'
Answered By - Fravadona Answer Checked By - Clifford M. (WPSolving Volunteer)