xml - String tokenisation algorithm won't tokenise -
morning all, writing bash script extract values of xml tags files in given directory. have decided tokenising each line , returning th4e relavent token. problem isn't tokenising correctly , can't quite work out why. here smallest example make reconstructs issue
#!/bin/bash file in `ls $my_directory` line in `cat $my_directory/$file` localifs=$ifs ifs=<>\" tokens=( $line ) ifs=$localifs echo "token 0: ${tokens[0]}" echo "token 1: ${tokens[1]}" echo "token 2: ${tokens[2]}" echo "token 3: ${tokens[3]}" done done
i'm guessing issue fiddling ifs inside loop uses ifs (i.e. cat operation), has never been problem before.
ideas?
thanks, rik
use better tool parse xml, ideally should parser, if requirement simple , know how xml structured, simple string manipulation might suffice. example, xml file , want value of tag3
$ cat file blah <tag1>value1 </tag1> <tag2>value2 </tag2> <tag3>value3 </tag3> blah $ awk -vrs="</tag3>" '/tag2/{ gsub(/.*tag3>/,"");print}' file value3
so iterate on directory
for file in *.xml value="$(awk -vrs="</tag3>" '/tag2/{ gsub(/.*tag3>/,"");print}' "$file" )" echo "$value" done
Comments
Post a Comment