Add all the A tasks
This commit is contained in:
parent
2dd7375f96
commit
051504d65b
1608 changed files with 18584 additions and 0 deletions
34
Task/Align-columns/AWK/align-columns.awk
Normal file
34
Task/Align-columns/AWK/align-columns.awk
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
BEGIN {
|
||||
FS="$"
|
||||
lcounter = 1
|
||||
maxfield = 0
|
||||
# justistification; pick up one
|
||||
#justify = "left"
|
||||
justify = "center"
|
||||
#justify = "right"
|
||||
}
|
||||
{
|
||||
if ( NF > maxfield ) maxfield = NF;
|
||||
for(i=1; i <= NF; i++) {
|
||||
line[lcounter,i] = $i
|
||||
if ( longest[i] == "" ) longest[i] = 0;
|
||||
if ( length($i) > longest[i] ) longest[i] = length($i);
|
||||
}
|
||||
lcounter++
|
||||
}
|
||||
END {
|
||||
just = (justify == "left") ? "-" : ""
|
||||
for(i=1; i <= NR; i++) {
|
||||
for(j=1; j <= maxfield; j++) {
|
||||
if ( justify != "center" ) {
|
||||
template = "%" just longest[j] "s "
|
||||
} else {
|
||||
v = int((longest[j] - length(line[i,j]))/2)
|
||||
rt = "%" v+1 "s%%-%ds"
|
||||
template = sprintf(rt, "", longest[j] - v)
|
||||
}
|
||||
printf(template, line[i,j])
|
||||
}
|
||||
print ""
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue