I have the file with the following content:
<rdf:RDF
xmlns:rdf="/www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="/xmlns.com/foaf/0.1/"
xmlns:jfs="//abc.net/xmlns/prod/xyz/jfs/1.0/">
<rdf:Description rdf:about="//alm.com/abc/users/piku">
<foaf:mbox rdf:resource="mailto:[email protected]"/>
<foaf:nick>piku</foaf:nick>
<foaf:name>Pallavi Mishra</foaf:name>
<jfs:archived rdf:datatype="//www.w3.org/2001/XMLSchema#boolean"
>false</jfs:archived>
<rdf:type rdf:resource="//xmlns.com/foaf/0.1/Person"/>
</rdf:Description>
</rdf:RDF>
Hoe can I extract email id '[email protected]' and name 'Pallavi Mishra' from this file using perl
or grep
.
My piece of code is:
my $Name = `cat abc.json | perl -l -ne '/<j.0:name>(.*)<\\/j.0:name>/ and print \$1'`;
my $EmailAddress = `cat abc.json | grep mailto | awk 'BEGIN{FS="\\"|:"} {for(i=1;i<NF;i++) if(\$i ~ /@/) print \$i}'`;
With
xmlstarlet
:For the name:
And for the email address:
You could add to the second one the
sed
statement to remove the mailto part: