#!/usr/bin/gawk -f BEGIN { FS=","; Pre="nasa93_"; Project=2; split("de,erb,gal,gro,hst,slp,spl,sts", Projects, ","); Category=3; split("application_ground,Avionics,avionicsmonitoring,batchdataprocessing,communications,datacapture,launchprocessing,missionplanning,monitor_control,operatingsystem,realdataprocessing,science,simulation,utility", Categories, ","); Fg=4; split("f,g", Fgs, ","); Center=5; split("1,2,3,5,6",Centers, ","); Year=6; split("1970,1975,1980,1985",Years,","); Mode=7; split("organic,semidetached,embedded",Modes,","); Rest=8; } NR<3 { line("all.csv"); hdr(Projects, "project"); hdr(Categories,"category"); hdr(Fgs, "fg"); hdr(Centers, "center"); hdr(Years, "year"); hdr(Modes, "mode"); } NR>2 { $6 = int($6/5)*5; line("all.csv"); data(Projects, Project, "project"); data(Categories,Category,"category"); data(Fgs, Fg,"fg"); data(Centers, Center,"center"); data(Years, Year, "year"); data(Modes, Mode, "mode"); } function hdr( x, z, i) { for(i in x) line(z "_" x[i] ".csv" ) } function data(x,y,z, i) { for(i in x) if ($y == x[i]) line(z "_" x[i] ".csv",1) } function line(what,append, str,sep,i) { str=sep=""; for(i=Rest;i<=NF;i++) { str=str sep $i; sep=","; } if (append) { print str>>Pre what; } else { print str>Pre what; } }