Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a matrix... can it be done? 1

Status
Not open for further replies.

kHz

MIS
Dec 6, 2004
1,359
US
I have a file that contains 46 servers and has a line for each group (this is a sample):

host1
root::0:root
other::1:
bin::2:root,bin,daemon
sys::3:root,bin,sys,adm
adm::4:root,adm,daemon
uucp::5:root,uucp
mail::6:root
tty::7:root,adm
lp::8:root,lp,adm
nuucp::9:root,nuucp
staff::10:
daemon::12:root,daemon
sysadmin::14:
smmsp::25:smmsp
nobody::60001:
noaccess::60002:
nogroup::65534:
dba::203:eek:racle,oracledba
access::227:usery,user2,user3,user4,userx,userN

host21
root::0:root
other::1:
bin::2:root,bin,daemon
sys::3:root,bin,sys,adm
adm::4:root,adm,daemon
uucp::5:root,uucp
mail::6:root
tty::7:root,adm
lp::8:root,lp,adm
nuucp::9:root,nuucp
staff::10:
daemon::12:root,daemon
sysadmin::14:
smmsp::25:smmsp
nobody::60001:
noaccess::60002:
nogroup::65534:
xyz::101:xyzadmin,user1

host23
root::0:root
other::1:
bin::2:root,bin,daemon
sys::3:root,bin,sys,adm
adm::4:root,adm,daemon
uucp::5:root,uucp
mail::6:root
tty::7:root,adm
lp::8:root,lp,adm
nuucp::9:root,nuucp
staff::10:
daemon::12:root,daemon
sysadmin::14:
smmsp::25:smmsp
nobody::60001:
noaccess::60002:
nogroup::65534:
xyz::101:xyzadmin

What I would like to have is a file that would end up with the top line containing the host and the side column listing the group with the GID under the appropriate host and in the corresponding row.

For example:

host1 host22 host23
root 0 0 0
other 1 1 1
xyz 101 101
access 207
dba 203
.
.
.

Not sure if this is possible, but I would like to know if it can be done, and how.

THANKS!

 
A starting point:
awk -F: '
NF==1{n=$1;th[++h]=n;next}
NF>3{g=$1;sub(/^ */,"",g);++tg[g];ta[n","g]=$3}
END{
for(i=1;i<=h;++i)printf "\t"th;printf "\n"
for(g in tg){
printf "%s",g
for(i=1;i<=h;++i)printf "\t"ta[th","g];printf "\n"
} }
' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you very much for your help. When I run it I am getting:
awk: syntax error near line 3
awk: illegal statement near line 3

I have looked and looked but I don't see where the syntax is.

THANKS!
 
Try nawk instead of awk.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
And if you don't have nawk, replace this:
sub(/^ */,"",g)
By this:
sub("^ *","",g)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
nawk worked!

Thank you very much!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top