jmoneygram jmoneygram - 9 months ago 36
Bash Question

How can I use 'sed' in a Linux Bash script file to comment out a particular line with tabbed spacing?

I wish to add '#' to the beginning of this line within a particular file using sed. The script will be run within a .sh file, not typed into the console.

auth [success=1 default=ignore] nullok_secure

Should be:

#auth [success=1 default=ignore] nullok_secure

I'm currently trying commands similar to:

sudo sed -e '/auth[[:tab:]][success=1[[:space:]]default=ignore][[:tab:]][[:space:]]nullok_secure/ s/^#*/#/' -i /etc/pam.d/common-auth

I know the above command is wrong, as
is not a valid command. I just want to show where the tabs occur.

Any help is appreciated!!! Thanks!!!


It works...

sed -e '/^auth\t\[success=1\ default=ignore\]\\ nullok_secure/ s/^/#/' -i file

I'm just using \t instead of [[:tab:]]

And \ instead of [[:space:]]