Last active
August 12, 2022 06:00
-
-
Save Spitfire1900/035a859a024c20b76a3a to your computer and use it in GitHub Desktop.
Parse XML in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
#xml parser, assigns entity to $E and content to $C | |
rdom () { local IFS=\> ; read -d \< E C ;} # https://stackoverflow.com/questions/893585/how-to-parse-xml-in-bash/7052168#7052168 | |
while rdom; do | |
if [[ $E = $2 ]]; then | |
echo $C | |
exit | |
fi | |
done < $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> | |
<Name>sth-items</Name> | |
<IsTruncated>false</IsTruncated> | |
<Contents> | |
<Key>[email protected]</Key> | |
<LastModified>2011-07-25T22:23:04.000Z</LastModified> | |
<ETag>"0032a28286680abee71aed5d059c6a09"</ETag> | |
<Size>1785</Size> | |
<StorageClass>STANDARD</StorageClass> | |
</Contents> | |
</ListBucketResult> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ ./parsexml.sh test.xml Key outputs "[email protected]"