Artificial intelligent assistant

print last field from line + alternative for awk 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

# Perl


echo foo bar baz | perl -pe 's/.*[ \t]//'


If you have to strip trailing spaces first, do it like this:


echo "foo bar baz " | perl -lpe 's/\s*$//;s/.*\s//'


The following was contributed by mr.spuratic in a comment:


echo "foo bar baz " | perl -lane 'print $F[-1]'


# Bash


echo foo bar baz | while read i; do echo ${i##* }; done


or is `bash` is not your default shell:


echo foo bar baz | bash -c 'while read i; do echo ${i##* }; done'


If you have to strip a single trailing space first, do


echo "foo bar baz " | while read i; do i="${i% }"; echo ${i##* }; done


# tr and tail


echo foo bar baz | tr ' ' '\
' | tail -n1


although this will only work for a single line of input, in contrast to the solutions above. Suppressing trailing spaces in this approach:


echo "foo bar baz " | tr ' ' '\
' | grep . | tail -n1

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 8d4186ddcee3fd5995d7fcd926a65cb9