for loop over input lines
Do it this way instead:
while IFS= read -r fecha; do
echo $fecha
done < <(xml2 < podcast | egrep "pubDate" | grep -Po "(?<=\=).*")
Bash will separate "words" to loop through by characters in the Internal Field Separator ($IFS
). You can temporarily disable this behavior by setting IFS
to nothing for the duration of the read
command. The pattern above will always loop line-by-line.
<(command)
makes the output of a command look like a real file, which we then redirect into our read
loop.
$ while IFS= read -r line; do echo $line; done < <(cat ./test.input)
Fri, 22 Jan 2016 17:56:29 +0100
Sun, 13 Dec 2015 18:33:02 +0100
Wed, 18 Nov 2015 15:27:43 +0100
xml2 < date_list | egrep "pubDate" | grep -Po "(?<=\=).*" \
| while read L
do
echo $L
done
read breaks on lines, and doesn't split words unless asked. :-)
However, tackling XML with regular expressions is bringing a knife to a gunfight. It's very easy to construct valid XML that the above pipeline will either miss, or capture incorrectly.
If you deal with much XML, you really want to get comfortable with a SAX parser.