Skip to main content
added 46 characters in body; edited title
Source Link
Michael Mrozek
  • 95.8k
  • 40
  • 245
  • 236

Perl or some other script do get data Parsing XML from filea shell script

Hello 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> 

So in script iI know the login name of the record I want, and iI need to match it to a group. Lets Let's say that iI want doto know what group name3name3 is (answerthe answer is group 3group 3)

 . Currently iI can get the name orof the group out ifof the file with =:

perl -ne 'print "$_\n" foreach /name="rsv-group-name".\ data="([^"])"/g;'

perl -ne 'print "$_\n" foreach /name="rsv-group-name".*\ data="([^"]*)"/g;' 

but iI have no idea how doto match it with a user. How can I do that in a script?

Perl or some other script do get data from file

Hello I have 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> 

So in script i know the name and i need to match it to group. Lets say that i want do know what group name3 is (answer is group 3)

  Currently i can get the name or the group out if the file with =

perl -ne 'print "$_\n" foreach /name="rsv-group-name".\ data="([^"])"/g;'

but i have no idea how do match it with a user.

Parsing XML from a shell script

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?

Source Link
Miq
  • 41
  • 2

Perl or some other script do get data from file

Hello I have 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> 

So in script i know the name and i need to match it to group. Lets say that i want do know what group name3 is (answer is group 3)

Currently i can get the name or the group out if the file with =

perl -ne 'print "$_\n" foreach /name="rsv-group-name".\ data="([^"])"/g;'

but i have no idea how do match it with a user.