Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does sed command contain at symbols

Tags:

sed

I don't understand why the following sed command contains an @ symbol:

sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

I've looked at /etc/pam.d/sshd for the before/after effects of this command:

BEFORE:

...
# Set the loginuid process attribute.
session    required     pam_loginuid.so
...

AFTER:

...
# Set the loginuid process attribute.
session optional pam_loginuid.so
....

Is the @ symbol possibly part of regex or sed syntax? Could not find any doco on this.

Note: The above sed command is actually part of a Dockerfile RUN command in tutorial: https://docs.docker.com/examples/running_ssh_service/

like image 477
Douglas Tyding Avatar asked Jan 27 '15 00:01

Douglas Tyding


People also ask

What are the special characters in sed?

The special character in sed are the same as those in grep, with one key difference: the forward slash / is a special character in sed. The reason for this will become very clear when studying sed commands.

How do you escape special characters in sed?

Sed needs many characters to be escaped to get their special meaning. For example, if you escape a digit in the replacement string, it will turn in to a backreference. Remember, if you use a character other than / as delimiter, you need replace the slash in the expressions above wih the character you are using.

What does the S mean in sed?

Substitution command In some versions of sed, the expression must be preceded by -e to indicate that an expression follows. The s stands for substitute, while the g stands for global, which means that all matching occurrences in the line would be replaced.

What does the sed command do?

The sed command, short for stream editor, performs editing operations on text coming from standard input or a file. sed edits line-by-line and in a non-interactive way. This means that you make all of the editing decisions as you are calling the command, and sed executes the directions automatically.


1 Answers

These are alternate delimiters for the regular expressions and replacement string. Handy when your regex or replacement string includes '/'.

like image 144
schtever Avatar answered Oct 21 '22 19:10

schtever