Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 08 Oct 2008 15:39:57 -0500
From:      Paul Schmehl <pschmehl_lists@tx.rr.com>
To:        Giorgos Keramidas <keramida@ceid.upatras.gr>, Kalpin Erlangga Silaen <kalpin@muliahost.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: bash script on FreeBSD
Message-ID:  <41A5AF34480F0D15F9F490B4@utd65257.utdallas.edu>
In-Reply-To: <87wsgidhjh.fsf@kobe.laptop>
References:  <48EC410C.2030707@muliahost.com> <87wsgidhjh.fsf@kobe.laptop>

next in thread | previous in thread | raw e-mail | index | archive | help
--On Wednesday, October 08, 2008 14:16:02 -0500 Giorgos Keramidas 
<keramida@ceid.upatras.gr> wrote:

>
> On Wed, 08 Oct 2008 12:11:40 +0700, Kalpin Erlangga Silaen
> <kalpin@muliahost.com> wrote:
>> Dear all,
>>
>> I am going to extract field username and UID from /etc/passwd and
>> passed into some scripts.  Let say I got line
>>
>> admin 100
>> admin2 200
>> admin3 300
>> admin4 400
>>
>> and then I want to echoing into screen:
>>
>> admin has uid 100
>> admin2 has uid 200
>> admin3 has uid 300
>> admin4 has uid 400
>>
>> How do I make this with bash script?
>
> You don't really need bash for this.
>
> Here's a sample awk script that should work:
>
>     % cat -n /tmp/userlist.awk
>          1  #!/usr/bin/awk -f
>          2
>          3  {
>          4          print $1,"has uid",$2;
>          5  }
>     % chmod 0755 /tmp/userlist.awk
>     % cat /tmp/user-data
>     admin 100
>     admin2 200
>     admin3 300
>     admin4 400
>     % /tmp/userlist.awk < /tmp/user-data
>     admin has uid 100
>     admin2 has uid 200
>     admin3 has uid 300
>     admin4 has uid 400
>     %

Sure, but why use an elephant to swat a flea when

awk 'FS=":"; {print $1" has uid "$3}' /etc/passwd | sort -k 4 -n

works fine and returns the accounts in numerical order?

-- 
Paul Schmehl, Senior Infosec Analyst
As if it wasn't already obvious, my opinions
are my own and not those of my employer.
*******************************************
Check the headers before clicking on Reply.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?41A5AF34480F0D15F9F490B4>