[CentOS] Extract lines from text file

Thu Aug 16 00:10:08 UTC 2012
Mark LaPierre <marklapier at aol.com>

On 08/15/2012 10:22 AM, Tony Molloy wrote:
>
> Hi,
>
> I'm looking for a command to extract lines from a large text file, a
> password file. A typical user has a username made from a letter
> followed by their id-number.
>
> m9718508:pw:9301:840: Lynch  :/home/pgstud/m9718508:/bin/bash
>
> So for instance if I need to extract lines where;
>
> the 1st field, the username begins with an m
> and
> the 4th field, the group contains exactly 850
>
> cat passwdfile | grep ^m | grep 850>  output
>
> is close but fails if the value 850 appears outside the 4th field. In
> the above example which should be ignored 850 appears in the username
> and home directory and is therefore extracted.
>
> Any ideas.
>
> Thanks,
>
> Tony
> _______________________________________________
> CentOS mailing list
> CentOS at centos.org
> http://lists.centos.org/mailman/listinfo/centos
>

[mlapier at mushroom ~]$ cat tmpfile
m9718508:pw:9301:840: Lynch  :/home/pgstud/m9718508:/bin/bash
m1234567:pw:9302:850: Lynch  :/home/pgstud/m1234567:/bin/bash

[mlapier at mushroom ~]$ grep ^m tmpfile | grep ":850:"
m1234567:pw:9302:850: Lynch  :/home/pgstud/m1234567:/bin/bash
[mlapier at mushroom ~]$

-- 
     _
    °v°
   /(_)\
    ^ ^  Mark LaPierre
Registerd Linux user No #267004
www.counter.li.org
****