LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Trying to Sort Two Files (https://www.linuxquestions.org/questions/linux-newbie-8/trying-to-sort-two-files-871337/)

rjdelight 03-27-2011 04:45 PM

Trying to Sort Two Files
 
I have two files (passwd.txt, group.txt) that I would like to take information out of and put into a new file. I would like to list all the users having a shell “/bin/bash” followed by a space separated list of all the groups each user belongs to. I'm brand new to Linux and just trying to organize some things and learn along the way. I would also like to have the new file in alphabetical order, if that is possible.

I don't think this is that complicated of a task, but since I'm a newb I could use the help. Thanks in advance!

markush 03-27-2011 05:09 PM

Hello rjdelight, welcome to LQ,

this looks like homework to me. We're not here to do your homework.

Could you please provide some information about what you've tried by yourself to solve your problem?

Markus

Tinkster 03-27-2011 06:33 PM

Quote:

Originally Posted by rjdelight (Post 4305534)
I have two files (passwd.txt, group.txt) that I would like to take information out of and put into a new file. I would like to list all the users having a shell “/bin/bash” followed by a space separated list of all the groups each user belongs to. I'm brand new to Linux and just trying to organize some things and learn along the way. I would also like to have the new file in alphabetical order, if that is possible.

I don't think this is that complicated of a task, but since I'm a newb I could use the help. Thanks in advance!

Two awks and a while-loop worked for me, makes a 5 line script.

Read up on "-F" in the context of awk, and on bash's while & read.



Cheers,
Tink

chrism01 03-28-2011 08:13 PM

You may find these useful
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html

grail 03-28-2011 11:32 PM

Come on Tink ... single awk is all you need ... lol

Tinkster 03-29-2011 01:06 AM

Quote:

Originally Posted by grail (Post 4307062)
Come on Tink ... single awk is all you need ... lol

True, but it loses some clarity


All times are GMT -5. The time now is 06:44 PM.