I am creating a shell script where I am using tr command to remove new line character and then use grep command to find dialog tag something like this
_linesContainingDialog="$(tr -s '\n' ' ' < $file | grep -oP '(?<=<af:dialog).*?(?= </af:dialog>)')"
When running this line alone in terminal
tr -s '\n' ' ' < $file | grep -oP '(?<=<af:dialog).*?(?= </af:dialog>)'
It gives me 7 distinct line
But when I run this in shell script and echo _linesContainingDialog, it gives me only one line. It seems, all 7 lines are jumbled up into one line when I run in shell script.
Request you to let me know what can I do different to get 7 distinct lines in shell script