Следуя ответу отсюда https://stackoverflow.com/questions/893585/how-to-parse-xml-in-bash, я сделал простой скрипт
#!/bin/bash
read_dom () {
local IFS=\>
read -d \< ENTITY CONTENT
}
found=0
while read_dom; do
if [[ $ENTITY = "ip-address" ]] && [[ $last_tag = "/hostname" ]] || [[ $ENTITY = "netmask" ]] || [[ $ENTITY = "default-gateway" ]]; then
if [[ $found = 0 ]]; then
echo "type=static"
fi
echo "$ENTITY=$CONTENT"
found="1"
fi
last_tag=$ENTITY
done
if [[ $found = 0 ]]; then
echo "type=dhcp-client"
fi
Если вы назовете свой скрипт parse.sh
, вы можете назвать его так
parse.sh < input.xml > output.txt