Transpose Tab-delimited Table for v2

Put simple Tips and Tricks that are not entire Tutorials in this forum
mbrandonpace
Posts: 3
Joined: 07 Dec 2017, 15:08

Transpose Tab-delimited Table for v2

Post by mbrandonpace » 17 Apr 2024, 11:56

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

Return to “Tips and Tricks”