commit 1fb885b94e493d9d36da5ddf5d2cd8fb8a99510f
parent df25f3ca6a4ccaf88f31117f4285cc16c39f526d
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Mon, 12 Jul 2021 14:46:49 +0200
add transpose program
Diffstat:
3 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
@@ -14,7 +14,8 @@ SCRIPTS = \
mean\
min\
rangetest\
- sum
+ sum\
+ transpose
MAN1 = ${SCRIPTS:=.1}
DOC = \
diff --git a/transpose b/transpose
@@ -0,0 +1,15 @@
+#!/usr/bin/awk -f
+{
+ for (i = 1; i <= NF; i++)
+ d[NR][i] = $i
+}
+END {
+ for (i = 1; i <= NF; i++) {
+ for (j = 1; j <= NR; j++) {
+ printf("%s", d[j][i])
+ if (j < NR)
+ printf("\t")
+ }
+ printf("\n")
+ }
+}
diff --git a/transpose.1 b/transpose.1
@@ -0,0 +1,28 @@
+.Dd $Mdocdate$
+.Dt TRANSPOSE 1
+.Os
+.Sh NAME
+.Nm transpose
+.Nd interchanges the row and column positions for each field
+.Sh SYNOPSIS
+.Nm
+.Op Ar file
+.Sh DESCRIPTION
+.Nm
+flips the rows and columns, effectively transposing it around the
+diagonal axis.
+This means that an input file with N colums and M rows is output as M
+colums and N rows.
+The input is
+.Ar file
+or standard input, if no
+.Ar file
+is given.
+.Sh SEE ALSO
+.Xr awk 1 ,
+.Xr max 1 ,
+.Xr mean 1 ,
+.Xr min 1 ,
+.Xr sum 1
+.Sh AUTHORS
+.An Anders Damsgaard Aq Mt anders@adamsgaard.dk