Использование XMLStarlet(иногда устанавливается как xmlstarlet
, а неxml
):
paths=( $( xml sel -t -v '//FileSetFolder/Path' file.xml ) )
for path in "${paths[@]}"; do
filetypes=( $( xml sel -t -v "//FileSetFolder[Path=\"$path\"]/FileType" file.xml ) )
for filetype in "${filetypes[@]}"; do
printf 'Path "%s" has a filetype "%s"\n' "$path" "$filetype"
done
done
Выход:
Path "D:\apache-2.4.10\htdocs" has a filetype "rep"
Path "D:\apache-2.4.10\htdocs" has a filetype "zip"
Path "D:\apache-2.4.10\htdocs" has a filetype "mnt"
Path "D:\Download\ROSXcenterAutoArchive\ArchiveStorage\archive" has a filetype "mnt"
Path "D:\Download\ROSXcenterAutoArchive\ArchiveStorage\archive" has a filetype "952230"