#!/usr/bin/gawk -f #/* vim: set filteype=awk : */ -*- awk -*- #Created by DJ Boland 11/28/06 BEGIN{ IGNORECASE=1; #make program case insensitive Ignore=1; #If True, at a point in the file to ignore(not output) Names=0; #If True, should be outputting to the .names file Data=0; #If True, should be outputting to the .data file Attrs=0; #Number of attributes in the class LastLine=""; #The attribute line read trimmedFile=""; #The file to put the trimmed file in searchString=ENVIRON["Selected"]; toKeep=0; Attrs=0; FS = " *, *" } {sub(/\%.*/,"")} {gsub(/[\'\"]/,"",$0)} /^[ \t\n]*$/ {next} /@relation/{ Ignore=0 Names=1 Data=0 split(FILENAME,fileparts, ".") trimmedFile=fileparts[1] "-trimmed.arff" print $0 > trimmedFile } /@attribute/{ Attrs++; LastLine=$0 split($0,names," ") if(match(searchString, names[2])) { print $0 >> trimmedFile toKeep++ Keep[toKeep]=Attrs } else{next} } /@data/{print LastLine >> trimmedFile; print $0 >> trimmedFile; Data=1; next} Data==1{ for(I=1; I <= toKeep; I++) { outAttr=Keep[I] # print outAttr # print $outAttr if(I==1) { output=$outAttr } else { output=output "," $outAttr } } output=output "," $NF print output >> trimmedFile } END{fflush(trimmedFile); close(trimmedFile)}