Due to technical reason on my Solaris machine, I can't use awk
in order to print the last field in line.
What are the other alternatives to awk
that print the last field from line (using cut
or tr
...etc)?
Example 1:
/usr/bin/hostname
machine1b
/usr/bin/hostname | /usr/bin/sed 's/\(.\{1\}\)/\1 /g' | /usr/bin/awk '{print $NF}'
b
Example2
echo 1 2 3 4 5 | /usr/bin/awk '{print $NF}'
5
sed
code seem you need the last character, not the last field. To get the hostname's last character inbash
,${HOSTNAME: -1}
may be enough. (Not sure if Solaris sets such variable.)