awk trailing character removal

Hi,

The command -

id | awk '{print $1}'
  • returns the following:
uid=9028(luke)

What do I need to further that awk so that I only have "

luke

", I want to set this as a variable.

Thanks in advance,
Lukas.

P.S: I've come up with:

USER1=`id | awk F'(' '{print $2}' | awk -F')' '{print $1}'`

This returns, "luke" but is there a better way of getting the same result?

try..

 
id|awk -F"[()]" '{gsub(/[0-9]/,"",$2);{print $2}}'
1 Like

Try

id -un

Not sure if this works with your version.

@vidyadhar85, I guess that gsub function is not really required:

id | awk -F'[()]' '{print $2}'

There might even be user names with numbers in them; that gsub would spoil them...