George M,
How about a 64% speed improvement (1.8s for lfs-dev book ..see below).
Is inline/in-script parsing next??
George B.
#----------------- cut -------------
#!/bin/bash
# script: XML pseudoparsing booster
declare -a filearray
declare -a filestore
declare -i linecounter
declare -i collectSTART=0
declare -i collectSTOP=0
declare -a chapterlist=(chapter05 \
chapter06 \
chapter07 \
chapter09);
for selectchapter in [EMAIL PROTECTED]
do
cd $selectchapter
echo $selectchapter
for filenameinput in *.xml
do
echo "-------------------------------------------------"
echo "x2sh:parsing file: "$filenameinput
echo "-------------------------------------------------"
while read filearray[linecounter]; do
((linecounter++))
done < "$filenameinput"
# Test for the following scenarios
# 1. <userinput> ... </userinput> inline definition
# 2. <userinput> spans in more lines
# 3. </userinput> ends spanning
#
for ((linecounter=0; linecounter < [EMAIL PROTECTED]; linecounter++));
do
case ${filearray[linecounter]} in
*\<userinput\>*)
if [[ "${filearray[linecounter]}" =~ '</userinput>' ]];
then #scenario 1
printf "%s\n" "${filearray[linecounter]}"
elif [[ ! "${filearray[linecounter]}" =~ '</userinput>' ]];
then #scenario 2
printf "%s\n" "${filearray[linecounter]}"
((collectSTART= linecounter + 1))
fi
;;
*\</userinput\>*) # scenario 3
((collectSTOP=linecounter++))
if [ $((collectSTOP - collectSTART)) -ge 1 ] ; then
for ((addthis=$collectSTART; addthis < $collectSTOP;
addthis++)); do
printf "%s\n" "${filearray[addthis]}"
done
fi
printf "%s\n" "${filearray[linecounter]}"
((collectSTOP=0))
((collectSTART=0))
;;
esac
done # for ((linecounter=0; linecounter.....
filearray=();
linecounter=0
done # for filenameinput in *.xml
cd ..
done # for selectchapter in ${chapterlist
#--------------- end cut ----------------
--
http://linuxfromscratch.org/mailman/listinfo/alfs-discuss
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page