[comp.sys.sgi] Result to awk question...

Claude.P.Cantin@NRC.CA (06/11/90)

From:         Claude.P.Cantin%NRC.CA@vm.nrc.ca
Subject:      awk question...
To:           info-iris@BRL.MIL
Message-ID:  <9006091601.aa04003@VGR.BRL.MIL>


>I'm writting a script in which a variable takes the value of a userid.
>I then want to find out who this userid refers to.

>I want to do that in one line, involving awk (I know how to do it using
>multiple lines of code).

>If the userid is 123, the following would do just fine:

>   awk -F: '$3 == 123 {print $1}' /etc/passwd

>BUT 123 is the content of a variable, say UID.  The following does NOT
>work:

>   awk -F: '$3 == $UID {print $1}' /etc/passwd

>(the output is NOTHING).

>I have tried several variations, including "$UID", and "$3"=="$UID", etc.,
>but none worked...

>Anyone has an insight????


Thanks to those who responded:  Those two variations both worked:



Well, you got close...try:  awk -F: '$3 == "'$UID'" {print $1}' /etc/passw

This works for  sh  or  csh.  Also, if you're on an SGI box, I recommend
"nawk" instead of "awk".

        awk -F: '$3 == '$UID' {print $1}' /etc/passwd



Special thanks to :

      Loki Jorgenson Rm421 <loki@Physics.McGill.CA>
      "Ronald B. Adams II" <texbell!redsim!adams@BRL.MIL>
      marcel@tnoibbc.ibbc.tno.nl (Marcel Boender)
      tim@ben.dciem.dnd.ca