1

I am trying to get information from an XML document and then taking that information and compare it to the information I am getting from a text document. But whenever I compare the number I receive from the XML to the number from the text document, the script always tells me they are not equal, even when they should be.

I am using xmllint to get the information from the XML document and read to get the number from the text document. Then I'm trying to compare them and if they're the same do something. But this is the point that I'm stuck at.

input_3="/Users/unix/Desktop/text.txt"
VAR_4= xmllint --xpath "string(//number)" /Users/unix/Desktop/01/testxml.xml
while IFS= read -r line
do
  if [[ "$VAR_4" == "$line" ]]
    then echo "YEAH"
    else echo "Why"
fi
done < "$input_3"

With this code, I always go into the else part of the statement even though the numbers should be the same. I have been working with echo to check the numbers to make sure they're the same and the only thing I could think of is that is has something to do with new lines or spaces. That either xmllint or read with IFS is putting a new line behind the number and that's the reason the script doesn't consider them the same. For example in my text document the number is 2, but I have to put a newline behind it, so read gets the number, and in the XML, the number is 2 too. I am hoping someone can maybe give me a clue about how I can change the format of the outputs I am getting or how to get the outputs on the same level.

kvantour
  • 25,269
  • 4
  • 47
  • 72
DeltaP
  • 29
  • 5

0 Answers0