Hi all,
Is Perl included by default in Ubuntu? I'm trying to write a program using as few languages as possible, and since I'm using a few Perl one-liners to do non-greedy matching, it's considered another language, and this is a bad thing.
Basically, I'm using a Perl one-liner to grab XML between tags, where $2 is the name of the tag and $3 is the nth tag with that name:
perl -pe "s/(.*?<$2>){$3}(.*?)<\/$2>.*/\2/"
To escape forward slashes in XML:
content=$(echo "$4" | perl -pe "s/<\//<\\\\\//")
And to grab an XML tag based on both its tag and content, where $2 is the name of the tag, $3 is the nth tag with that name, and $content is an XML string escaped as above:
perl -pe "s/(.*?<$2>){$3}(.*$content.*?)<\/$2>.*/\2/"
I can't use sed because it doesn't have non-greedy matching, I can't use grep because it doesn't have non-greedy matching without Perl-like extensions, and to my knowledge Bash cannot do something this complicated on its own.
Does anyone know of another way I can do this, so it's not "another language" we have to use to maintain with?
Thanks,
Zel2008