#!/usr/bin/nawk -f # # Usage: coll2unix profile field [field [...]] # # Typical command line: # # java xmlpipe xmlfile | coll2unix http://org/profile field1 field2 # # First argument (profile) selectes the records. Only records in the # Web Collection with the right profile will be output, others are # skipped. The list of fields then selects the fields in that record # and gives the order in which they will be output. The result is a # list of records, one per line, with fields separated by tabs. BEGIN { the_profile = ARGV[1]; for (i = 2; i < ARGC; i++) column[i-1] = ARGV[i]; nrcolumns = ARGC - 2; ARGC = 1; #for (i = 1; i <= nrcolumns; i++) { # printf "%s", column[i]; # if (i < nrcolumns) printf "\t"; else printf "\n"; #} } $1 == "APROFILE" {profile = $2; next;} $1 == "ANAME" {name = $2; next;} $1 == "AVALUE" {value = substr($0, 8); next;} $1 == "(FIELD" {field[name] = value; next;} $1 == ")RECORD" { if (profile == the_profile) { for (i = 1; i <= nrcolumns; i++) { printf "%s", field[column[i]]; if (i < nrcolumns) printf "\t"; else printf "\n"; } } for (i in field) delete field[i]; next; }