Anders Johansson wrote:
On Wednesday 25 March 2009 20:40:49 David C. Rankin wrote:
You are on to something. While I counted 45 lines in konsole, evidently "They're not lines." Here is what I see on konsole:
14:23 alchemy:~/linux/scripts/parse> sh xmlparse test.xml.gz | nl <snip> Any other thoughts??
Could you post the xmlparse script?
ANders
Anders, I would be glad to now. 20 minutes ago I would have been a wee-bit embarrassed. I found the culprit. (ducking...) there was a stray echo. Since the test.xml.gz file only contained 5 xml blocks from the repository metadata file deltainfo.xml.gz and the xml schema for the files has, at a maximum, 9 entries that make up each xml block, the stray echo was just in the exact perfect place to produce 45 blank likes (5 blocks x 9 entries per block = 45 blank lines generated. However, it is fixed now and I can now build my custom deltainfo.xml.gz from the master file at openSuSE Updates by parsing the master file for filenames that exist on my local update repository and when a matching rpm is found the xml block for that rpm is written to my deltainfo.xml.gz. Beats the hell out of cutting and pasting from a 370,000 line xml file. Sorry about the fat-finger error on my part here, but I really do appreciate the help. Also, if anyone else is running their own local update server for local machines, this script is worth it weight in gold. In case anybody else can make use of it, here it is: #!/bin/bash --norc ## ## Title: ## Name: ## Usage: ## Version: 0.0.1 ## Date: 03/23/2009, 04:53:03 PM ## Author: David C. Rankin, J.D.,P.E ## Summary: ## ## Run as: ## Requires: http://ftp5.gwdg.de/pub/opensuse/update/11.0/repodata/deltainfo.xml.gz ## ## #. /home/david/linux/scripts/include/general.inc #. /home/david/linux/scripts/include/colors.inc ## # usage () { echo -e "\n\tUsage: ${0##*/} filename.xml.gz [newfile.xml]\n" echo -e "\tThis script parses the openSuSE deltainfo.xml.gz XML file and" echo -e "\ttests if the filenames contained are present in the local update" echo -e "\trepository. If the file is present, then the XML block for the" echo -e "\tfilename is written to a newfile to create the local deltainfo.xml.gz" echo -e "\tfile.\n" } cleanup () { [[ -e $NEWFILE ]] && gzip --force --quiet $NEWFILE [[ -e $XMLFILE ]] && gzip --force --quiet $XMLFILE } trap cleanup SIGINT SIGTERM EXIT writexml () { for (( i=$PATCHINFO; i < ${#ENTRY[@]}; i++ )); do if [[ -n $1 ]]; then OUTFILE=$1 case $i in 3 ) echo "<filename>${RPMDIR}/${ENTRY[$i]}</filename>" >> $OUTFILE;; 5 ) echo "<size>${ENTRY[$i]}</size>" >> $OUTFILE;; * ) echo "${ENTRY[$i]}" >> $OUTFILE;; esac else case $i in 3 ) echo "<filename>${RPMDIR}/${ENTRY[$i]}</filename>";; 5 ) echo "<size>${ENTRY[$i]}</size>";; * ) echo "${ENTRY[$i]}";; esac fi done } [[ ! -r $1 ]] && { echo -e "\n Unable to read file: '${1:-"[NoneGiven]"}', \ exiting...\n"; usage; exit 1; } [[ ! $1 =~ '.gz' ]] && { echo -e "\n\tInvalid File Format. The file supplied: $1 \ is not a valid GNU zip file, exiting...\n"; exit 1; } let CLINE=0 DLINE=0 BLOCKNO=0 HEADERLINES=2 declare -a ENTRY LOCDELTA XMLFILEGZ=$1 XMLFILE=${XMLFILEGZ%.gz} NEWFILE=${2:-"out-$(date '+%s').xml"} REMHOST=nirvana REMDIR=/home/backup/rpms/openSUSE_11.0/delta FOOTER="</deltainfo>\n" PATCHINFO=1 BLOCKDONE=no DEBUG=no ERRLOG=${3:-${XMLFILE%%.*}.err} [[ ! -r /tmp/deltafiles ]] && ssh $REMHOST "ls -1 $REMDIR" > /tmp/deltafiles while IFS=$'\n' read line; do LOCDELTA[$DLINE]=$line # echo "[$DLINE] ${LOCDELTA[$DLINE]}" ((DLINE+=1)) done < /tmp/deltafiles gunzip $XMLFILEGZ --force --quiet while IFS=$'\n' read line; do ((CLINE+=1)) if [[ $CLINE -le "$HEADERLINES" ]]; then echo $line >> $NEWFILE else case ${line:1:2} in !- ) ENTRY[0]=$line PATCHINFO=0;; ne ) ENTRY[1]=$line;; de ) ENTRY[2]=$line;; fi ) tmpline=${line%<*} tmpline=${tmpline#*>} RPMDIR=${tmpline%/*} ENTRY[3]=${tmpline##*/};; se ) ENTRY[4]=$line;; si ) tmpline=${line%<*} ENTRY[5]=${tmpline##*>};; ch ) ENTRY[6]=$line;; /d ) ENTRY[7]=$line;; /n ) ENTRY[8]=$line BLOCKDONE=yes;; * ) echo -e "\n\terror: No tag match in block: $BLOCKNO, line: $CLINE\n";; esac # check if BLOCKDONE=yes if [[ $BLOCKDONE == 'yes' ]]; then ((BLOCKNO+=1)) # check if file exists for ((j=0;j<=${#LOCDELTA[@]};j++)); do if [[ ${ENTRY[3]} == ${LOCDELTA[$j]} ]]; then # writexml writexml $NEWFILE fi done # reset block and loop control variables BLOCKDONE=no PATCHINFO=1 fi fi done < $XMLFILE ((CLINE+=1)) echo -ne $FOOTER >> $NEWFILE exit 0 If you don't like the line wrapping here, you can download the script directly from: http://www.3111skyline.com/download/linux/scripts/xmlparse -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org