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?
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?
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/^[^.]+\.//'
sed
– Rahul Sep 02 '16 at 09:58domain_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 02 '16 at 10:21