Re: [CentOS] Extract lines from text file

2012-08-16 Thread Tony Molloy
On Wednesday 15 August 2012 20:53:33 m.r...@5-cent.us wrote:
 Tony Molloy wrote:
  On Wednesday 15 August 2012 19:46:42 Les Mikesell wrote:
  On Wed, Aug 15, 2012 at 1:26 PM, Tony Molloy tony.mol...@ul.ie
 
  wrote:
   ]$ 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.
 
  sed -n -e '/pattern/p' can match anything grep would do and
  might be even more useful if you want substitutions for
  subsequent use. And of course perl can do anything sed can do,
  and then some...
 
  True true, and of course C could do anything and everything ;-)
 
  But all I need is a simple script which will be run once a year
  to remove the graduated students from the password file.
 
 Ah, but are you sure they're not just dropped out for a term, or
  about to become indentured servants, er, grad students? In that
  case, maybe just change their login shell to /bin/noLogin
 
   mark
 

No these are 4th year graduated students. If they stay on as post 
graduate students they have to re-register. So clean them out I say 
;-)

Tony
 
 
 ___
 CentOS mailing list
 CentOS@centos.org
 http://lists.centos.org/mailman/listinfo/centos
 
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-16 Thread wwp
Hello m.r...@5-cent.us,


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

 wwp wrote:
  On Wed, 15 Aug 2012 15:22:10 +0100 Tony Molloy tony.mol...@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


signature.asc
Description: PGP signature
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


[CentOS] Extract lines from text file

2012-08-15 Thread Tony Molloy

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@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-15 Thread Rajagopal Swaminathan
Greetings,

On Wed, Aug 15, 2012 at 7:52 PM, Tony Molloy tony.mol...@ul.ie wrote:

 Hi,


 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


cut -d: -f1,4 input-filename

-- 
Regards,

Rajagopal
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-15 Thread wwp
Hello Tony,


On Wed, 15 Aug 2012 15:22:10 +0100 Tony Molloy tony.mol...@ul.ie 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.

Something like `grep -E '^m.+:.*:.*:850:'` maybe?


Regards,

-- 
wwp


signature.asc
Description: PGP signature
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-15 Thread Marcelo Beckmann
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



-- 
Marcelo Beckmann
Suporte Corporativo - supo...@webers.com.br
Webers Tecnologia - http://www.webers.com.br
Curitiba   (PR) (41) 3094-6600
Rio de Janeiro (RJ) (21) 4007-1207
São Paulo  (SP) (11) 4007-1207


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-15 Thread m . roth
wwp wrote:
 On Wed, 15 Aug 2012 15:22:10 +0100 Tony Molloy tony.mol...@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

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-15 Thread Tony Mountifield
In article 81eb30fb297893749f5c1e211f08c7e4.squir...@mail.5-cent.us,
 m.r...@5-cent.us wrote:
 wwp wrote:
  On Wed, 15 Aug 2012 15:22:10 +0100 Tony Molloy tony.mol...@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

awk -F: '{ if ($1 ~ /^m/  $4 == 850 ) { print $0;}}' /etc/passwd

Cheers
Tony
-- 
Tony Mountifield
Work: t...@softins.co.uk - http://www.softins.co.uk
Play: t...@mountifield.org - http://tony.mountifield.org
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-15 Thread m . roth
Tony Mountifield wrote:
 In article 81eb30fb297893749f5c1e211f08c7e4.squir...@mail.5-cent.us,
  m.r...@5-cent.us wrote:
 wwp wrote:
  On Wed, 15 Aug 2012 15:22:10 +0100 Tony Molloy tony.mol...@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

 awk -F: '{ if ($1 ~ /^m/  $4 == 850 ) { print $0;}}' /etc/passwd

Or
awk 'BEGIN { FS=:;}{ if ($1 ~ /^m/  $4 == 850 ) { print $0;}}'
/etc/passwd

mark

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-15 Thread Tilman Schmidt
Am 15.08.2012 16:36, schrieb Marcelo Beckmann:
 Em 15-08-2012 11:22, Tony Molloy escreveu:
[...]
 cat passwdfile | grep ^m | grep 850  output
[...]
 ]$ cat testcentoslist | egrep ^m.*:.*:.*:850:

http://en.wikipedia.org/wiki/Cat_%28Unix%29#Useless_use_of_cat

Because a cat is a terrible thing to waste.

SCNR,
T.
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-15 Thread m . roth
Tilman Schmidt wrote:
 Am 15.08.2012 16:36, schrieb Marcelo Beckmann:
 Em 15-08-2012 11:22, Tony Molloy escreveu:
 [...]
 cat passwdfile | grep ^m | grep 850  output
 [...]
 ]$ cat testcentoslist | egrep ^m.*:.*:.*:850:

 http://en.wikipedia.org/wiki/Cat_%28Unix%29#Useless_use_of_cat

 Because a cat is a terrible thing to waste.

And why would you want to disturb our Lords  Masters? I mean, why are
*we* here?

  mark

--
The truth is out, we know at last:
  Dogs have masters, cats have staff.

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-15 Thread Tony Molloy
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
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-15 Thread Les Mikesell
On Wed, Aug 15, 2012 at 1:26 PM, Tony Molloy tony.mol...@ul.ie wrote:

 ]$ 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.


sed -n -e '/pattern/p' can match anything grep would do and might be
even more useful if you want substitutions for subsequent use.  And of
course perl can do anything sed can do, and then some...

-- 
  Les Mikesell
lesmikes...@gmail.com
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-15 Thread Tony Molloy
On Wednesday 15 August 2012 19:46:42 Les Mikesell wrote:
 On Wed, Aug 15, 2012 at 1:26 PM, Tony Molloy tony.mol...@ul.ie 
wrote:
  ]$ 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.
 
 sed -n -e '/pattern/p' can match anything grep would do and might
  be even more useful if you want substitutions for subsequent use. 
  And of course perl can do anything sed can do, and then some...
 

True true, and of course C could do anything and everything ;-)

But all I need is a simple script which will be run once a year to 
remove the graduated students from the password file.

Regards,

Tony
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-15 Thread m . roth
Tony Molloy wrote:
 On Wednesday 15 August 2012 19:46:42 Les Mikesell wrote:
 On Wed, Aug 15, 2012 at 1:26 PM, Tony Molloy tony.mol...@ul.ie
 wrote:
  ]$ 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.

 sed -n -e '/pattern/p' can match anything grep would do and might
  be even more useful if you want substitutions for subsequent use.
  And of course perl can do anything sed can do, and then some...


 True true, and of course C could do anything and everything ;-)

 But all I need is a simple script which will be run once a year to
 remove the graduated students from the password file.

Ah, but are you sure they're not just dropped out for a term, or about to
become indentured servants, er, grad students? In that case, maybe just
change their login shell to /bin/noLogin

  mark



___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Extract lines from text file

2012-08-15 Thread Mark LaPierre
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@centos.org
 http://lists.centos.org/mailman/listinfo/centos


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

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

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

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos