Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Oct 2008 08:21:21 +0100
From:      Frank Shute <frank@shute.org.uk>
To:        Kalpin Erlangga Silaen <kalpin@muliahost.com>, freebsd-questions@freebsd.org
Subject:   Re: bash script on FreeBSD
Message-ID:  <20081008072121.GB94922@melon.esperance-linux.co.uk>
In-Reply-To: <20081008071156.GA94922@melon.esperance-linux.co.uk>
References:  <48EC410C.2030707@muliahost.com> <20081008071156.GA94922@melon.esperance-linux.co.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Oct 08, 2008 at 08:11:56AM +0100, Frank Shute wrote:
>
> On Wed, Oct 08, 2008 at 12:11:40PM +0700, Kalpin Erlangga Silaen 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?
> > 
> > Thank you
> > 
> > 
> > Kalpin Erlangga Silaen
> 
> $ sed -e 's/\(admin[0-9]*\)\ \([0-9]*\)/\1 has uid \2/g' /etc/passwd
> 

Correction: You can't use that on /etc/passwd directly. But assuming
you've got a file already in the format you specified, then you can
use it on that.

If you want to grab the data directly from /etc/passwd then you'd be
better off using awk(1).

Regards,

-- 

 Frank 


 Contact info: http://www.shute.org.uk/misc/contact.html 




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