I was splitting the output from
id to provide a more readable line-by-list list of groups of which a user is a member:
id roaima | sed 's/,/\n\t/g' uid=1001(roaima) gid=1001(roaima) groups=1001(roaima) 24(cdrom) 25(floppy) ... 822413650 (international (uk) location)
I wanted to separate the group number from its bracketed name so I extended the expression like this
id roaima | sed -e 's/,/\n\t/g' -e '2,$s/(/ (/'
However, this did not act as I initially expected. The second expression appeared to have no effect.
Instead, to get the result I wanted, I needed to run two separate
sed commands, like this:
id roaima | sed -e 's/,/\n\t/g' | sed '2,$s/(/ (/' uid=1001(roaima) gid=1001(roaima) groups=1001(roaima) 24 (cdrom) 25 (floppy) ... 822413650 (international (uk) location)
Why do I need two
sed commands in a pipe rather than one with multiple instructions? Or if I can do this with one
sed, how would I do so?
What I would particularly like is to have the single space between the UID/GID value and its bracketed name for every single item (including the UID and GIDs on the first line), but the caveat is that in my real data I can have groups containing brackets in their names and I don't want the names themselves mangled.