[CentOS] Extract lines from text file

Wed Aug 15 18:26:39 UTC 2012
Tony Molloy <tony.molloy at ul.ie>

On Wednesday 15 August 2012 15:36:09 Marcelo Beckmann wrote:
> Em 15-08-2012 11:22, Tony Molloy escreveu:
> > 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.
> 
> ]$ cat testcentoslist
> m9718508:pw:9301:840: Lynch  :/home/pgstud/m9718508:/bin/bash
> m9718308:pw:9301:850: Lynch  :/home/pgstud/m9718508:/bin/bash
> m9718208:pw:9301:840: Lynch  :/home/pgstud/m9718508:/bin/bash
> m9718508:pw:9301:840: Lynch  :/home/pgstud/m9718908:/bin/bash
> 
> ]$ cat testcentoslist | egrep ^m.*:.*:.*:850:
> m9718308:pw:9301:850: Lynch  :/home/pgstud/m9718508:/bin/bash
> 

Exactly what I needed. I'll just drop the cat as a later poster 
pointed out.

Thanks to all who replied.

Tony