Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Nov 2001 17:32:54 +0200
From:      Giorgos Keramidas <charon@labs.gr>
To:        Odhiambo Washington <wash@wananchi.com>
Cc:        questions@freebsd.org
Subject:   Re: Help with AWK
Message-ID:  <20011110153254.GA12138@hades.hell.gr>
In-Reply-To: <20011110094234.B1578@ns2.wananchi.com>
References:  <20011109194842.E27386@ns2.wananchi.com> <3BEC628A.5050005@verizon.net> <20011110094234.B1578@ns2.wananchi.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--tThc/1wpZn/ma/RB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Odhiambo Washington <wash@wananchi.com> wrote
> * Simon Morton <simon.morton@verizon.net> [20011110 02:17]:
> | If I understand correctly, the following should do it
> |
> | awk -F: '$4==40{printf "^%s@.*\\.wananchi.com$:%s$:%s/:\n",$1,$3,$2;}'
>
> Hello Simon,
>
> That is not it ;). That line gives the following
>
> #^user@.*\.wananchi.com3552YZb2gtYJeEZ1Y/
>
> What I want (from master.passwd) are the following fields with the extra
>
> ^$1@.*\.wananchi.com$:$3:$2
>
> $1 = login id
> $2 = encrypted passwd
> $3 = numerical UID
>
> All with colon as the separator.
>
> I need to extract those details for two groups of users - staff (GID==20) and wheel (GID==0),
> all in one command, if possible.

a) Use egrep to limit the lines of master.passwd that interest you.
   (Not that it makes a great difference, but this way you separate
   the problem in two smaller problems: selecting lines, and printing
   those we selected with a format).

	egrep -e '^[^:]*:[^:]*:[^:]*:(20|0):.*$' master.passwd

b) Then print only those fields you're interested in with awk's printf().

	awk '{printf "^%s@.*\\.wananchi.com$:%s:%s\n",$1,$3,$2}'

Testing this on my machine prints:

	# egrep -e '^[^:]*:[^:]*:[^:]*:(20|0):.*$' master.passwd | \
	  awk -F: '{printf "^%s@.*\\.wananchi.com$:%s:%s\n",$1,$3,$2}'
	^root@.*\.wananchi.com$:0:PASSWORD


--tThc/1wpZn/ma/RB
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (FreeBSD)

iD8DBQE77Uim1g+UGjGGA7YRAi/zAKCIwTDW1l/cje2QQ/nUithCBw8UEwCgsFmg
jw/3bh9FsF5K/5M6JqmIHzo=
=jq1+
-----END PGP SIGNATURE-----

--tThc/1wpZn/ma/RB--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




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