Using a single Awk:
... | awk -F '[/:]' '{print $5}'
That is, using as field separator either /
or :
, the username is always in field 5.
To store it in a variable:
username=$(... | awk -F '[/:]' '{print $5}')
A more flexible implementation with sed
that doesn't require username to be field 5:
... | sed -e s/:.*// -e s?.*/??
That is, delete everything from :
and beyond, and then delete everything up until the last /
. sed
is probably faster too than awk
, so this alternative is definitely better.