0
I use the following syntax in order to capture only the number from machine hostname
echo machineLinux05 | sed s'/\./ /g' | awk '{print $1}' | sed 's/[^0-9]//g'
05
But this way is not so elegant. Is there another short alternative to capture the number from the string?
1What is the purpose of
sed s'/\./ /g' | awk '{print $1}'
? In your example, neither of these commands does anything. – John1024 – 2017-12-31T07:28:12.120the purpose is in case hostname have also the domain name as machineLinux05.FG.com – enodmilvado – 2017-12-31T08:22:36.970
2
tr -cd '[0-9]' <<< "machineLinux05"
– Cyrus – 2017-12-31T10:38:33.0531
echo machineLinux05.FG,com | grep -o '[0-9]\+'
also works. – Paulo – 2017-12-31T13:36:41.527