Tmux doesn't have a command to show windows in the active session. So I'm trying to parse Tmux's windows in the active session. I've got a unique table sorted by date (field 1).

dump_tmux_info() {
    tmux list-panes -a -F "#{session_activity} #{session_name} #{window_index} #{window_name}"

# sort--> unique numbers descending (mru) --> unique fields3 (wind. order)
dump_tmux_info | sort -k1,1nr -u -k3 -u 


1473706992 SessionF 1 windF
1473706992 SessionI 2 windO
1473706992 SessionZ 3 windO
1473706992 SessionZ 4 windB
1473699283 SessionZ 1 windZ

What I'm trying to do...

  1. Match all fields based on [line 1,field 1] OR [line 1,field 2] OR max values in field 1 (either work) and remove the rest.
  2. List matching window names in an ordered numeric array. windF windO windO windB

I've tried looking at AWK but I can't see how to access multidimensional arrays elements.


1 Answer 1


To find all the 4th-column values for the max value of column 1:

dump_tmux_info |
 sort -k1,1nr -u -k3 -u |
 awk '
    NR == 1 || $1 > max {max = $1; maxv = sep = ""} 
    $1 == max {maxv = maxv sep $NF; sep = " "} 
    END {print maxv}


windF windO windO windB
  • I've tested this, and it works! Just to clarify, why does the statement maxv = maxv sep $NF default to the last field when it would substitute to maxv = "" " " 4. Does $NF move it to the last field? Commented Sep 13, 2016 at 16:47
  • NF without the dollar is the number of fields in the current record. Phrased differently, NF is the number of the last field. When you add the dollar, you get the value of the last field. Similarly, if you assign a number to a variable, then express the variable with a dollar, you get the value of that field: echo "foo bar baz" | awk '{x=2; print x; print $x}' Commented Sep 13, 2016 at 20:18
  • This lets you do interesting things, like get the 2nd last value ($(NF-1)), or do things with pairs of fields: for (i=1; i<NF; i+=2) {a=$i; b=$(i+1); some_function(a,b)} Commented Sep 13, 2016 at 20:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .