#!/usr/bin/gawk -f BEGIN { FS=","; Pre="coc81_"; Mode=2; split("e,sd,org", Modes, ","); Type=3; split("bus,ctl,hmi,sci,sup,sys", Types, ","); Lang=4; split("cob,ftn,hol,jov,mol,pl1,psc", Langs, ","); Kind=5; split("max,mid,min", Kinds, ","); Rest=6; } NR< 3 { line("all.csv"); hdr(Modes, "mode"); hdr(Types, "type"); hdr(Langs, "lang"); hdr(Kinds, "kind"); } NR>2 { line("all.csv"); data(Modes,Mode, "mode"); data(Types,Type, "type"); data(Langs,Lang, "lang"); data(Kinds,Kind, "kind"); } 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; } }