[CentOS] Extract lines from text file

Thu Aug 16 09:10:35 UTC 2012
wwp <subscript at free.fr>

Hello m.roth at 5-cent.us,


On Wed, 15 Aug 2012 11:47:21 -0400 m.roth at 5-cent.us wrote:

> wwp wrote:
> > On Wed, 15 Aug 2012 15:22:10 +0100 Tony Molloy <tony.molloy at ul.ie> wrote:
> >>
> >> 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.
> >
> > Something like `grep -E '^m.+:.*:.*:850:'` maybe?
> 
> Complicated.
> 
> awk '{ if ($1 ~ /^m/ && $4 == "850" ) { print $0;}}' /etc/passwd
> 
>     mark "awk! awk!*"
> 
> * No, I'm still not a seagull....

I found that regexp particularly simple :-D. Not here to troll, but
simple or complicated, I think it's only about a bit of knowledge
(understanding), a learning curve. Personally I don't feel comfortable
w/ awk expressions/language. Not saying that one if better than the
other - I would rather think that knowing both is way better. Don't be
afraid with regular expressions, there's nothing really complex about
most of them!


Regards,

-- 
wwp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.centos.org/pipermail/centos/attachments/20120816/8d1f873a/attachment-0005.sig>