I'm trying to use grep to remove the comments from a file, smb.conf to be specific, and bash is giving me an error. I found this question How to remove all comments from a file? that gives the syntax for grep to do this, but it doesn't overwrite the file, it just prints it to the terminal. I would like to effectively overwrite the file. This is what's going on:
$ sudo grep -o '^[^#]*' /etc/samba/smb.conf >> /etc/samba/smb.conf
-bash: /etc/samba/smb.conf: Permission denied
I have done something like this before, but then I was following an online guide and I vaguely remember having to start up bash before I could grep. Obviously, I can't find that guide again.
How do you use grep to strip out the comments from a file?
I'm working on a Raspberry Pi B+ running Raspbian Jessie.
>>
redirection, at which point it is your user shell. redirect it to a file you can write to, then sudo mv it; or sudo vi the file and pipe its contents to the grep – Jeff Schaller Feb 09 '16 at 00:54sed
is a better approach (using-i
) – Thomas Dickey Feb 09 '16 at 00:55