I’m trying to reformat the output of the last command e.g. last -adn 10 | head -n -2 | awk -F' {2,}' '{ print "USER:",$1,"IP:",$5 }'.
>> last -adn 10 | head -n -2
root pts/0 Tue Jul 10 13:51 still logged in 10.102.11.34
reboot system boot Fri Jun 22 09:37 (18+04:19) 0.0.0.0
I would like my output to be something like:
>>last -adn 10 | head -n -2 | awk -F' {2,}' '{ print "USER:",$1,"IP:",$5 }'
USER: root IP: 10.102.11.34 TIME: Tue Jul 10 13:51
I’ve tried every method described here, and I can’t figure out why this is not working for me.
When executing that command, it simply stores the whole line in $1, and the others are blank.
By default, gawk does not enable interval expressions. You can enable them with the
--re-intervalflag. Other versions of awk may or may not support them at all.If you can’t enable the flag, you can use a more explicit match. For example: