1

This question already has an answer here:

Today I've come across this command for extracting domain name from domain controller's FQDN:

DOMAIN_NAME=$(echo $DC_PC | sed -r 's!^[^.]+\.!!')

What is the meaning of these exclamation marks in sed? How does it work?

marked as duplicate by Thomas Dickey, Archemar, GAD3R, Jeff Schaller, Julie Pelletier Sep 2 '16 at 15:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • That is called as Delimiter in sed – Rahul Sep 2 '16 at 9:58
  • 2
    Or just domain_name=${DC_PC#*.} (strictly speaking the equivalent would be ${DC_PC#[!.]*.} because of that + which is I don't think was intended) which would be a lot more portable, efficient and reliable. – Stéphane Chazelas Sep 2 '16 at 10:21
2

The first character after s is used as the separator for the parameters to s, so this replaces anything matching ^[^.]+\. with the empty string. Traditionally this would be written

sed -r 's/^[^.]+\.//'

Not the answer you're looking for? Browse other questions tagged or ask your own question.