csv.md

@include "au"

function csv(i,file,row,header,fs,rs,        
             pat,fs0,rs0,txts,txt,cells,n,what) {
  header = header ? header : row
  fs0  = FS
  rs0  = RS
  n    = 0
  FS   = fs  ? fs : ","
  RS   = rs  ? rs : "\n"
  file = file ? file : "/dev/stdin"
  pat  = "#"DOT"*"
  while((getline txt < file) > 0)  {
     gsub(/[ \t\r]*/, "", txt) # no whitespace:
     gsub(pat,     "", txt) # no comments
     if (txt) {
       txts = txts txt
       if (txts !~ /,$/) {
         split(txts, cells, FS)
         txts = ""
         what = n ? row : header
	       @what(i,n,cells)
         n++ }}}
  close(file)
  FS= fs0
  RS= rs0
}