Last active
August 7, 2022 00:18
-
-
Save gregmark/05ac2a108f8151539df9f538330a17db to your computer and use it in GitHub Desktop.
p2columns.awk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# p2columns.awk | |
# ------------- | |
# * aligns two-field output into two even columns | |
# * column width will equal the number of characters in the longest first-field | |
# string plus the value of the variable p | |
# * by default, p (padding) == 1 | |
# * change padding with -v p=N, e.g. to increase padding to 3 spaces: | |
# | |
# awk -v p=3 -f awk-script input-file | |
# | |
BEGIN { | |
if (! p) p = 1 | |
n = 0; | |
}; | |
{ | |
x = length($1); | |
if (x > n) n = x; | |
a[NR] = $0; | |
}; | |
END { | |
n += p; | |
for ( i = 1; i <= NR; i++ ) { | |
split(a[i], z); | |
printf "%-"n"s%s\n", z[1], z[2]; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment