i am building a database to keep track of unix groups.
Using the command "ypcat group"
I get an output similar to the following
group1:GROUP:9999:user1,user2,user3
groupA:GROUP:1111:usera,userb,userc
I want to convert this output so it looks like this
group1:user1
group1:user2
group1:user3
groupA:usera
groupA:userb
groupA:userc
using two sed commands i've gotten to this point
ypcat group | sed 's#:.*:.*:#:\n#g' | sed 's#,#\n#g'
This gets me to here:
group1:
user1
user2
user3
groupA:
usera
userb
userc
I know there is a way to preappend the group lines to the other lines with the hold function in sed but i can't seem to get it right. There is also probably an awk command to accomplish this.
The sed command should look similar to this but it has no affect:
sed '#:#{hd}G'