I have a datafile like this:
<Key name="com.ahsay.afc.cpf.UserGroup" content="" allowMultiple="Y">
<Value name="rsv-id" inheritParentAttribute="Y" type="string" data="1328200856753" />
<Value name="rsv-group-name" inheritParentAttribute="Y" type="string" data="group 1" />
<Value name="rsv-user-type" inheritParentAttribute="Y" type="string" data="backup-user" />
<Value name="rsv-owner" inheritParentAttribute="Y" type="string" data="" />
<Key name="com.ahsay.afc.cpf.User" content="" allowMultiple="Y">
<Value name="rsv-id" inheritParentAttribute="Y" type="string" data="13279083887401" />
<Value name="rsv-login-name" inheritParentAttribute="Y" type="string" data="name1" />
</Key>
<Key name="com.ahsay.afc.cpf.User" content="" allowMultiple="Y">
<Value name="rsv-id" inheritParentAttribute="Y" type="string" data="13279083887401" />
<Value name="rsv-login-name" inheritParentAttribute="Y" type="string" data="name2" />
</Key>
</Key>
<Key name="com.ahsay.afc.cpf.UserGroup" content="" allowMultiple="Y">
<Value name="rsv-id" inheritParentAttribute="Y" type="string" data="1328200856753" />
<Value name="rsv-group-name" inheritParentAttribute="Y" type="string" data="group 2" />
<Value name="rsv-user-type" inheritParentAttribute="Y" type="string" data="backup-user" />
<Value name="rsv-owner" inheritParentAttribute="Y" type="string" data="" />
<Key name="com.ahsay.afc.cpf.User" content="" allowMultiple="Y">
<Value name="rsv-id" inheritParentAttribute="Y" type="string" data="13279083887401" />
<Value name="rsv-login-name" inheritParentAttribute="Y" type="string" data="name3" />
</Key>
<Key name="com.ahsay.afc.cpf.User" content="" allowMultiple="Y">
<Value name="rsv-id" inheritParentAttribute="Y" type="string" data="13279083887401" />
<Value name="rsv-login-name" inheritParentAttribute="Y" type="string" data="name4" />
</Key>
</Key>
I know the login name of the record I want, and I need to match it to a group. Let's say I want to know what group name3
is (the answer is group 3
). Currently I can get the name of the group out of the file with:
perl -ne 'print "$_\n" foreach /name="rsv-group-name".*\ data="([^"]*)"/g;'
but I have no idea how to match it with a user. How can I do that in a script?