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
Greetings,
On Wed, Aug 15, 2012 at 7:52 PM, Tony Molloy tony.molloy@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>
Hello Tony,
On Wed, 15 Aug 2012 15:22:10 +0100 Tony Molloy tony.molloy@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 wrote:
On Wed, 15 Aug 2012 15:22:10 +0100 Tony Molloy tony.molloy@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....
In article 81eb30fb297893749f5c1e211f08c7e4.squirrel@mail.5-cent.us, m.roth@5-cent.us wrote:
wwp wrote:
On Wed, 15 Aug 2012 15:22:10 +0100 Tony Molloy tony.molloy@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 wrote:
In article 81eb30fb297893749f5c1e211f08c7e4.squirrel@mail.5-cent.us, m.roth@5-cent.us wrote:
wwp wrote:
On Wed, 15 Aug 2012 15:22:10 +0100 Tony Molloy tony.molloy@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
Hello m.roth@5-cent.us,
On Wed, 15 Aug 2012 11:47:21 -0400 m.roth@5-cent.us wrote:
wwp wrote:
On Wed, 15 Aug 2012 15:22:10 +0100 Tony Molloy tony.molloy@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,
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
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.
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.
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
On Wed, Aug 15, 2012 at 1:26 PM, Tony Molloy tony.molloy@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...
On Wednesday 15 August 2012 19:46:42 Les Mikesell wrote:
On Wed, Aug 15, 2012 at 1:26 PM, Tony Molloy tony.molloy@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
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.molloy@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
On Wednesday 15 August 2012 20:53:33 m.roth@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.molloy@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
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 ~]$