Skip to content

Commit

Permalink
added transpose
Browse files Browse the repository at this point in the history
  • Loading branch information
0ki committed Sep 15, 2024
1 parent dd744af commit 6e2f350
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This section is included because it may be impossible to understand what some of
* `striptags` removes HTML tags
* `tar.nometa [params]` creates a tar archive without any metadata
* `toplines [-n]` show most prevalent lines and their count; prints top n lines
* `transpose` transposes IFS separated table
* `trimn` removes trailing newline(s) from input
* `unbuffer <command>` disables output buffering for commands that can't do that natively
* `urldecode` decodes URL encoded characters (RFC3986)
Expand Down
17 changes: 17 additions & 0 deletions transpose
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
awk '
{
for (i = 1; i <= NF; i++) {
matrix[i, NR] = $i
}
rows = NR
cols = NF
}
END {
for (i = 1; i <= cols; i++) {
for (j = 1; j <= rows; j++) {
printf "%s ", matrix[i, j]
}
print ""
}
}'

0 comments on commit 6e2f350

Please sign in to comment.