Case 1
Get the hostname 'AAA' from a FQDN 'AAA.BBB.CCC.DDD.EEE'.
Script and Comments
Script1 [sed]
[ 1] s/\..*//
Script2 [perl]
[ 1] $fqdn = 'AAA.BBB.CCC.DDD.EEE';
[ 2] $hostname = $fqdn;
[ 3] $hostname =~ s/\..*//;
[ 4] print "$hostname\n";
Case 2
Get the domain name 'BBB.CCC.DDD.EEE' from a FQDN 'AAA.BBB.CCC.DDD.EEE'.
Script and Comments
Script1 [sed]
[ 1] s/[^.]*\.//
Script2 [perl]
[ 1] $fqdn = 'AAA.BBB.CCC.DDD.EEE';
[ 2] $domainname = $fqdn;
[ 3] $domainname =~ s/.*?\.//;
Case 3
Get the last part 'EEE' of a FQDN 'AAA.BBB.CCC.DDD.EEE'.
Script and Comments
Script1 [sed]
[ 1] s/.*\.//
Script2 [perl]
[ 1] $fqdn = 'AAA.BBB.CCC.DDD.EEE';
[ 2] $last = $fqdn;
[ 3] $last =~ s/.*\.//;