robust command (latest CSV, fixed indexing)

This script automatically identifies the latest CSV results file and uses AWK to parse complex columns, calculate confidence intervals (LB/UB), and reformat the output for easier analysis. It handles dynamic slot counts and ends with a sorted summary.
anil0w0 avatar
anil0w0
sh
02/17/2026 11:00 PM
1.2 KB
12
Indexable
latest=$(ls -t results_*.csv | head -1)

awk -F, '
NR==1 {
  # number of source slots from header
  nslots = (NF - 4) / 3
  next
}

$NF==1 {
  p = $(NF-2)
  comp = $(NF-1)

  src_start = 2
  wt_start  = 2 + nslots
  se_start  = wt_start + nslots

  minLB = 100
  maxUB = 0

  for(i=0;i<nslots;i++){
    w = $(wt_start+i); gsub("%","",w)
    e = $(se_start+i); gsub("%","",e)

    if(w == "" || w == "0") continue

    lb = w - (2*e)
    ub = w + (2*e)

    if(lb < minLB) minLB = lb
    if(ub > maxUB) maxUB = ub
  }

  # header
  printf "%.3f [LB=%.1f%%] [UB=%.1f%%] %s", p, minLB, maxUB, $1

  # sources
  for(i=0;i<nslots;i++) printf ", %s", $(src_start+i)

  # weights
  printf " | W:"
  for(i=0;i<nslots;i++) printf " %s", $(wt_start+i)

  # SEs
  printf " | SE:"
  for(i=0;i<nslots;i++) printf " %s", $(se_start+i)

  printf " | p=%.3f C=%d\n", p, comp
}' "$latest" \
| sort -k1,1gr
Editor is loading...
Leave a Comment