Page 1 of 1

Transpose Tab-delimited Table for v2

Posted: 17 Apr 2024, 11:56
by mbrandonpace
Here's one way to transpose a tab-delimited table, say from Notepad. To use the following script, first copy a table to the clipboard, then press F1 to transpose and paste.

Code: Select all

f1::
; transposes and pastes a tab-delimited table from clipboard
; AHK v2.0
{
table := a_clipboard
loop parse, table, "`n", "`r"
{
  loop parse, a_loopfield, "`t"
    lastline := a_index
  break
}
loop lastline
{
  i := a_index
  for a, b in strsplit(table,"`n","`r")
    for c, d in strsplit(b,"`t")
      if c = i
        newtable .= d "`t"
  newtable .= "`n"
}
sendinput newtable
}
So, if you copy the following the clipboard:

a	b	c
d	e	f
g	h	i
j	k	l


Pressing F1 will transpose and paste like so:

a	d	g	j
b	e	h	k
c	f	i	l