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!

Something similar to a spreadsheet 1

Status
Not open for further replies.

kHz

MIS
Dec 6, 2004
1,359
US
For a variation of my previous question that created a matrix that worked perfectly, is it possible to use the data below to create a different type of matrix?

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 is something similar to this:

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

THANKS!!
 
Code:
BEGIN {
  FS = "::?"
}

1==NF { name = $1; next }

NF>2 {
  key = $1 " " $2
  table[key] = table[key] " " name
}

END {
  for (key in table)
    print key table[key]
}
Let me know whether or not this helps.

If you have nawk, use it instead of awk because on some systems awk is very old and lacks many useful features. Under Solaris, use /usr/xpg4/bin/awk.

For an introduction to Awk, see faq271-5564.
 
I think NF>2 should be NF>1:
Code:
BEGIN {
  FS = "::?"
}

1==NF { name = $1; next }

NF>1 {
  key = $1 " " $2
  table[key] = table[key] " " name
}

END {
  for (key in table)
    print key table[key]
}
 
The NF>1 worked perfectly!

Thanks!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top