Sorry, a minor copy / paste error will eat a line while parsing (the $((collectSTOP + 1)) variable) , so please use the one below, thanks:

# ----------------------------------CUT HERE---------------------

#!/bin/bash

# script: XML pseudoparsing booster
# license: GPL 2.x and up
# author: George Makrydakis <[EMAIL PROTECTED]>


declare -a filearray
declare -a filestore
declare -i linecounter
declare -i collectSTART=0
declare -i collectSTOP=0

declare -a chapterlist=(chapter01 \
                        chapter02 \
                        chapter03 \
                        chapter04 \
                        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
                let "linecounter++"
        done < "$filenameinput"

# case scenarios:
# <userinput> ... </userinput> inline definition
# <userinput> spans in more lines
# </userinput> ends spanning
#

        for ((linecounter=0; linecounter < [EMAIL PROTECTED]; linecounter++));
        do
        if [[ "${filearray[linecounter]}" =~ '<userinput>' ]] && \
           [[ "${filearray[linecounter]}" =~ '</userinput>' ]] ; #scenario 1
        then
                        printf "%s\n" "${filearray[linecounter]}"
        elif [[ "${filearray[linecounter]}" =~ '<userinput>' ]] && \
             [[ ! "${filearray[linecounter]}" =~ '</userinput>' ]] ; #scenario 2
        then
                        printf "%s\n" "${filearray[linecounter]}"
                        let "collectSTART= linecounter + 1"
        elif [[ ! "${filearray[linecounter]}" =~ '<userinput>' ]] && \
             [[  "${filearray[linecounter]}" =~ '</userinput>' ]] ; #scenario 3
        then
        let "collectSTOP=linecounter"
        let "linecounter++"
        if [ $((collectSTOP - collectSTART)) -ge 1 ] ;
        then
for ((addthis=$collectSTART; addthis < $((collectSTOP + 1)); addthis++));
        do
                printf "%s\n" "${filearray[addthis]}"
        done
        fi
                        printf "%s\n" "${filearray[linecounter]}"
                        let "collectSTOP=0"
                        let "collectSTART=0"
        fi
        done
        filearray=();
        linecounter=0
        done
        cd ..
done

# ----------------------------------CUT ENDS---------------------

--
http://linuxfromscratch.org/mailman/listinfo/alfs-discuss
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to