FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 08-15-2012, 02:22 PM
Tony Molloy
 
Default Extract lines from text file

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.

m9718508w: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
 
Old 08-15-2012, 02:31 PM
Rajagopal Swaminathan
 
Default Extract lines from text file

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>

--
Regards,

Rajagopal
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 08-15-2012, 02:33 PM
wwp
 
Default Extract lines from text file

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.
>
> m9718508w: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
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 08-15-2012, 02:36 PM
Marcelo Beckmann
 
Default Extract lines from text file

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.
>
> m9718508w: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
m9718508w:9301:840: Lynch :/home/pgstud/m9718508:/bin/bash
m9718308w:9301:850: Lynch :/home/pgstud/m9718508:/bin/bash
m9718208w:9301:840: Lynch :/home/pgstud/m9718508:/bin/bash
m9718508w:9301:840: Lynch :/home/pgstud/m9718908:/bin/bash

]$ cat testcentoslist | egrep ^m.*:.*:.*:850:
m9718308w:9301:850: Lynch :/home/pgstud/m9718508:/bin/bash



--
Marcelo Beckmann
Suporte Corporativo - suporte@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
 

Thread Tools




All times are GMT. The time now is 04:01 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org