[Question]
  [
This challenge is similar to [this old
one](https://codegolf.stackexchange.com/q/3783/3808), but with some unclear
parts of the spec hammered out and less strict I/O requirements.
---
Given an input of a string consisting of only printable ASCII and newlines,
output its various metrics (byte, word, line count).
The metrics that you must output are as follows:
* Byte count. Since the input string stays within ASCII, this is also the
character count.
* Word count. This is `wc`'s definition of a "word:" any sequence of
non-whitespace. For example, `abc,def"ghi"` is one "word."
* Line count. This is self-explanatory. The input will always contain a
trailing newline, which means line count is synonymous with "newline
count." There will never be more than a single trailing newline.
The output must exactly replicate the default `wc` output (except for the file
name):
```
llama@llama:~$ cat /dev/urandom | tr -cd 'A-Za-z \n' | head -90 > example.txt
llama@llama:~$ wc example.txt
  90  165 5501 example.txt
```
Note that the line count comes first, then word count, and finally byte count.
Furthermore, each count must be left-padded with spaces such that they are all
the same width. In the above example, `5501` is the "longest" number with 4
digits, so `165` is padded with one space and `90` with two. Finally, the
numbers must all be joined into a single string with a space between each
number.
Since this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), the shortest code in bytes will win.
(Oh, and by the way... you can't use the `wc` command in your answer. In case that wasn't obvious already.)
Test cases (`\n` represents a newline; you may optionally require an extra
trailing newline as well):
```
"a b c d\n" -> "1 4 8"
"a b c d e f\n" -> " 1  6 12"
"  a b c d e f  \n" -> " 1  6 16"
"a\nb\nc\nd\n" -> "4 4 8"
"a\n\n\nb\nc\nd\n" -> " 6  4 10"
"abc123{}[]()...\n" -> " 1  1 16
"\n" -> "1 0 1"
"   \n" -> "1 0 4"
"\n\n\n\n\n" -> "5 0 5"
"\n\n\na\nb\n" -> "5 2 7"
```
  
[Answer]
# Perl, 49 bytes
Added +3 for `-an0`
Input on STDIN or 1 or more filenames as arguments.
Run as `perl -an0 wc.pl`
`wc.pl`:
```
/\z/g;pos=~//;printf"%@+d %@+d $`
",y/
//,~~@F
```
Explanation:
```
-n0      slurps the whole input into $_ and says we will do our own printing
-a       tells perl to split the input on whitespace into array @F
/\z/g    Matches the absolute end of the input. g modifier so the position 
         is remembered in pos which will now contain the input length
pos=~//  An empy regex repeats the last succesful match, so /\z/ again.
         After that $` will contain the the number of input characters and
         the array @+ will contain the length of this number
printf   All preparation is complete, we can go print the result
"%@+d"   will become e.g. %6d if the number of characters is a number of
         length 6, so lines and words will get printed right aligned 
         in a field of length 6.
$`       $` we can directly interpolate since it won't contain a %
y/\n//   Count the number of newlines in $_
~~@F     The array of words @F in scalar context gives the number of words
```
[Answer]
# Pyth, 21 bytes
```
jdm.[;l`lQ`ld[@bQcQ)Q
```
[Test suite](https://pyth.herokuapp.com/?code=jdm.%5B%3Bl%60lQ%60ld%5B%40bQcQ%29Q&test_suite=1&test_suite_input=%22a+b+c+d%5Cn%22%0A%22a+b+c+d+e+f%5Cn%22%0A%22++a+b+c+d+e+f++%5Cn%22%0A%22a%5Cnb%5Cnc%5Cnd%5Cn%22%0A%22a%5Cn%5Cn%5Cnb%5Cnc%5Cnd%5Cn%22%0A%22abc123%7B%7D%5B%5D%28%29...%5Cn%22%0A%22%5Cn%22%0A%22+++%5Cn%22%0A%22%5Cn%5Cn%5Cn%5Cn%5Cn%22%0A%22%5Cn%5Cn%5Cna%5Cnb%5Cn%22&debug=0)
Pyth has some very nice built-ins here. We start by making a list (`[`) of the newlines in the string (`@bQ`), the words in the string (`cQ)`) and the string itself (`Q`). Then, we pad (`.[`) the length of each string (`ld`) with spaces (`;` in this context) out to the length of the number of characters (`l`lQ`). Finally, join on spaces (`jd`).
[Answer]
# Python 2, ~~100~~ 77 bytes
This solution is a Python function that accepts a multi-line string and prints the required counts to stdout. Note that I use a format string to build a format string (which requires a `%%` to escape the first format placeholder).
*Edit: Saved 23 bytes due to print optimisations by Dennis.*
```
def d(b):c=len(b);a='%%%us'%len(`c`);print a%b.count('\n'),a%len(b.split()),c
```
Before the minifier, it looks like this:
```
def wc(text) :
    size = len(text);
    numfmt = '%%%us' % len(`size`);
    print numfmt % text.count('\n'), numfmt % len(text.split()), size
```
[Answer]
# POSIX awk, 79 75 67 65 bytes
```
{w+=NF;c+=length+1}END{d=length(c)"d %";printf"%"d d"d\n",NR,w,c}
```
Edit: saved 4 bytes since POSIX allows a bare `length`, saved 7 bytes by discounting the invocation part, and saved two bytes thanks to Doorknob's tip for adding `d %` to `d`.
This was originally for GNU awk, but best I can tell, it uses only POSIX awk functionality.
Better formatted:
```
gawk '{
  w += NF
  c += length($0) + 1  # length($0) misses the newline
}
END {
  d = length(c) # GNU awk's length returns the length of string representation of number
  printf "%"d"d %"d"d %d\n", NR, w, c
}'
```
[Answer]
## [Seriously](https://github.com/Mego/Seriously), 39 bytes
```
"
 "╩╜l;$l╝@╜sl'
╜ck`#╛#"{:>%d}"%f`M' j
```
[Try it online!](http://seriously.tryitonline.net/#code=IgogIuKVqeKVnGw7JGzilZ1A4pWcc2wnCuKVnGNrYCPilZsjIns6PiVkfSIlZmBNJyBq&input=ImFiYzEyM3t9W10oKS4uLlxuIg)
Explanation (newlines are replaced with `\n`):
```
"\n "╩╜l;$l╝@╜sl'\n╜ck`#╛#"{:>%d}"%f`M' j
"\n "                                      push a string containing a newline and a space
     ╩                                     push input to register 0 (we'll call it s)
      ╜l;                                  push two copies of len(s) (byte count)
         $l╝                               push len(str(len(s))) to register 1
                                            (this will serve as the field width in the output)
            @╜sl                           push word count by getting the length of the list formed by
                                            splitting s on spaces and newlines
                '\n╜c                      count newlines in input
                     k                     push stack to list
                      `#╛#"{:>%d}"%f`M     map:
                       #                     listify
                        ╛#                   push reg 1 (field width), listify
                          "{:>%d}"           push that string
                                  %          do old-style string formatting for field width
                                   f         do new-style string formatting to pad the field appropriately
                                      ' j  join on spaces
```
[Answer]
# AppleScript, 253 bytes
This assumes that AppleScript's text item delimiters are set to space (if I need to count the stuff to force that assumption, I'll add it).
```
set w to(display dialog""default answer"")'s text returned
set x to b(w)
set y to w's text item's number
set z to w's paragraph's number
a(x,z)&z&a(x,y)&y&" "&x
on a(x,n)
set o to" "
repeat b(x)-b(n)
set o to o&" "
end
o
end
on b(n)
count(n as text)
end
```
[Answer]
# CJam, ~~31~~ 26 bytes
```
q_)/_S*S%@_]:,:s),f{Se[}S*
```
[Try it online!](http://cjam.tryitonline.net/#code=cV8pL19TKlMlQF9dOiw6cyksZntTZVt9Uyo&input=YWJjMTIze31bXSgpLi4uCg)
### How it works
```
q_                         e# Read all input from STDIN and push two copies.
  )                        e# Pop the last character (linefeed) of the second copy.
   /                       e# Split the remaining string at linefeeds.
    _                      e# Push a copy.
     S*                    e# Join the copy, separating by spaces.
       S%                  e# Split at runs of spaces.
         @_                e# Rotate the original input on top and push a copy.
           ]               e# Wrap all four items in an array.
            :,             e# Get the length of each item.
              :s           e# Cast the lengths (integers) to strings.
                )          e# Pop the last length (byte count).
                 ,         e# Get the number of digits.
                  f{Se[}   e# Left-pad all three length with spaces to that length.
                        S* e# Join, separating by spaces.
```
[Answer]
# Julia, ~~112~~ 81 bytes
```
f(s,n=endof,l="$(n(s))",g=r->lpad(n(split(s,r))-1,n(l)))=g(r"\n")" "g(r"\S+")" "l
```
This is a function that accepts a string and returns a string.
We save the following as function arguments:
* `n = endof` function, which gets the last index of an indexable collection (in this case is the length of the string)
* `l = "$(n(s))`, the length of the input converted to a string using interpolation
* A lambda function `g` that accepts a regular expression and returns the length - 1 of the input split on that regex, left padded with spaces to match the length of `l`.
We get the number of lines using `g(r"\n")` and the number of words using `g(r"\S+")`, then we join those together with `l` delimited by spaces.
Saved 31 bytes thanks to Dennis!
[Answer]
# MATL, 38 bytes
```
'\n'32cZtttnGnw-wPZvPYbnqbnvvV!3Z"vX:!
```
You can [try it online!](http://matl.tryitonline.net/#code=J1xuJzMyY1p0dHRuR253LXdQWnZQWWJucWJudnZWITNaInZYOiE&input=JyAgYSBiIGMgZCBlIGYgIFxuJw)
This shouldn't be so long though...
Explanation, for the calculation,
```
'\n'32cZt  %// Takes implicit input and replaces any \n with a space
tt         %// Duplicate that string twice
nGnw-w     %// Length of the string with \n's minus length with spaces to give number of \n's
PZvPYbnq   %// Take string with spaces, flip it, remove leading spaces, flip it again,
           %// split on spaces, find length and decrement for number of words
bn         %// get length of string with spaces, the number of characters
```
The last part does the output formatting
```
vvV!       %// concatenate the 3 numbers to a column vector, convert to string and transpose
3Z"v       %// make string '   ' and concatenate on the bottom of previous string
X:!        %// linearise and transpose to get correct output (impicitly printed)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 14 bytes
```
»⁶Ḳ¹ƇLṭċ⁷$;LWG
```
[Try it online!](https://tio.run/##ATcAyP9qZWxsef//wrvigbbhuLLCucaHTOG5rcSL4oG3JDtMV0f///8iICBhIGIgYyBkIGUgZiAgXG4i "Jelly – Try It Online")
-1 thanks to [Dennis](https://codegolf.stackexchange.com/users/12012/dennis).
[Answer]
## JavaScript (ES6), 115 bytes
```
s=>[/\n\/g,/\S+/g,/[^]/g].map(r=>l=(s.match(r)||[]).length).map(n=>(' '.repeat(99)+n).slice(-`${l}`.length)).join` `
```
Does not require any input. Formatting was painful. If there was an upper limit on the amount of padding I could reduce `(' '.repeat(99)+n)` to something shorter e.g. `` ${n}``.
[Answer]
## PowerShell, 140 bytes
```
param($a)$c="$((($l=($a-split"`n").Count-1),($w=($a-split"\S+").Count-1),($b=$a.length)|sort)[-1])".Length;
"{0,$c} {1,$c} {2,$c}"-f$l,$w,$b
```
(newline left in for clarity :D)
The first line takes input `$a`, and then the next part is all one statement. We're setting `$c` equal to *some-string's* `.length`. This will form our requisite padding. Inside the string is an immediate code block `$(...)`, so that code will be executed before evaluated into the string.
In the code block, we're sending three items through the `|sort` command, and then taking the biggest one `(...)[-1]`. This is where we're ensuring to get the columns to the correct width. The three items are `$l` the line count, where we `-split` on newlines, the `$w` word count, where we `-split` on whitespace, and `$b` the length.
The second line is our output using the `-f` operator (which is a pseudo-shorthand for `String.Format()`). It's another way of inserting expanded variables into strings. Here, we're saying that we want all of the output to be padded to the left so that each column is `$c` wide. The padding is done via spaces. The `0`, `1`, and `2` correspond to the `$l`, `$w`, and `$b` that are arguments to the format operator, so the line count, word count, and byte count are padded and output appropriately.
Note that this either requires the string to have already-expanded newlines (e.g., doing a `Get-Content` on a text file or something, and then either piping or saving that to a variable, then calling this code on that input), or use the PowerShell-styled escape characters with backticks (meaning  ``n` instead of `\n`).
**Example**
```
PS C:\Tools\Scripts\golfing> .\reimplement-wc.ps1 "This line`nis broken`ninto three lines.`n"
 3  7 38
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip) `-s`, 25 bytes
```
sX##a-#_._M[nNa`\S+`Na#a]
```
Takes the multiline string as a command-line argument. [Try it online!](https://tio.run/##K8gs@P@/OEJZOVFXOV4v3jc6zy8xISZYO8EvUTkx9v///7rF/xO5uLiSuJK5UrgA "Pip – Try It Online")
*Thanks to [Dennis's CJam answer](https://codegolf.stackexchange.com/a/74227/16766) for making me realize that the longest number is always the character count.*
### Explanation
```
                           s is space; n is newline; a is 1st cmdline arg (implicit)
           [            ]  Construct a list of three elements:
            nNa             Number of newlines in a
               `\S+`Na      Regex search: number of runs of non-whitespace characters in a
                      #a    Length of a (i.e. number of characters in a)
          M                To each element of that list, map this function:
   #a                       Number of characters in a
  #                         Length of that number
     -#_                    Subtract length of each element
sX                          Construct a string of that many spaces
        ._                  Prepend it to the element
                           The resulting list is autoprinted, space-separated (-s flag)
```
---
Here's a 29-byte solution with flags `-rs` that takes input from stdin:
```
[#g`\S+`NST:gY#g+1]MsX#y-#_._
```
[Try it online!](https://tio.run/##K8gs@P8/Wjk9ISZYO8EvOMQqPVI5Xdsw1rc4QrlSVzleL/7//0QuLq4krmSuFIVUrv@6RcUA "Pip – Try It Online")
[Answer]
# Powershell, ~~123~~ 115 bytes
```
switch -r($args|% t*y){'\s'{$a=0}'\S'{$w+=!$a;$a=1}'(?s).'{$b++}'
'{$l++}}$c="$b".Length
"{0,$c} {1,$c} $b"-f$l,+$w
```
Test script:
```
$f = {
switch -r($args|% t*y){    # evaluate all matched cases
    '\s'   {$a=0}          # any whitespace (newline not included)
    '\S'   {$w+=!$a;$a=1}  # any not-whitespace (newline not included)
    '(?s).'{$b++}          # any char (newline included!)
    '`n'   {$l++}          # new line char
}
$c="$b".Length
"{0,$c} {1,$c} $b"-f$l,+$w
}
@(
    , ("a b c d`n", "1 4 8")
    , ("a b c d e f`n", " 1  6 12")
    , ("  a b c d e f  `n", " 1  6 16")
    , ("a`nb`nc`nd`n", "4 4 8")
    , ("a`n`n`nb`nc`nd`n", " 6  4 10")
    , ("abc123{}[]()...`n", " 1  1 16")
    , ("`n", "1 0 1")
    , ("   `n", "1 0 4")
    , ("`n`n`n`n`n", "5 0 5")
    , ("`n`n`na`nb`n", "5 2 7")
) | % {
    $s,$e = $_
    $r = &$f $s
    "$($e-eq$r): $r"
}
```
Output:
```
True: 1 4 8
True:  1  6 12
True:  1  6 16
True: 4 4 8
True:  6  4 10
True:  1  1 16
True: 1 0 1
True: 1 0 4
True: 5 0 5
True: 5 2 7
```
Explanation:
* `$args|% t*y` splits arument strings into chars
* `switch -r($args|% t*y)` evaluate *all matched cases*
	+ `'\s'` case for any whitespace
	+ `'\S'` case for any non-whitespace
	+ `'(?s).'` case for any char (newline included)
	+ `'\n'` case for newline char (newline represent itself)
* `$c="$b".Length` calculate a length of bytes number. $b is always max($l,$w,$b) by design
* `"{0,$c} {1,$c} $b"-f$l,+$w` format numbers with same length. The variable $w converts to int. It need for strings without words. Other variables formats 'as is' because 'The input will always contain a trailing newline' and $l and $b cannot be 0.
[Answer]
## Pascal, 248 bytes
This complete `program` requires a processor supporting “Extended Pascal” as defined by ISO standard 10206.
* The variable `input` possesses the built-in data type `text`.
As such any newline character (sometimes it’s CR, sometimes LF, sometimes CR+LF, or something else) is *automagically* converted into a single space character (`' '`).
In order to distinguish from a space character as *payload* of a line, and a space character that resulted from this conversion, you will need to query the function `EOLn`.
* A `text` variable is conceptually similar to a `file of char`.
This `program` in fact counts *characters*, i. e. actually behaves like `wc ‑m`.
However, since the task states that characters strictly draw from the ASCII character set, there is no difference.
```
program c(input,output);var l,w,c,z:integer value 0;p:char;begin p:=' ';while not EOF do begin c:=c+1;l:=l+ord(EOLn);w:=w+card([p]*[' ','   ']-[input^]);p:=input^;get(input)end;z:=trunc(ln(card([0..l,0..w,0..c]))/ln(10))+2;writeLn(l:z-1,w:z,c:z)end.
```
Ungolfed and annotated version:
```
{ By listing a `program` parameter of the spelling `input`,
  there’s an implicit `reset(input)` which implies a `get(input)`. }
program wordCount(input, output);
    var
        { `line`, `word` and `character` are singular, because they kind
          of enumerate these units as if input was a zero-based `array`. }
        line, word, character, width: integer value 0;
        previousCharacter: char;
    begin
        { This program counts “word beginnings” as words. This is the
          _change_ from “space character” _to_ “non-space character”. }
        previousCharacter := ' ';
        
        while not EOF(input) do
        begin
            character := character + 1;
            { As per POSIX specification a line is payload _plus_ one newline. }
            line := line + ord(EOLn(input));
            { The second character literal is an HT (horizontal tabulator). }
            word := word + card([previousCharacter] * [' ', '   '] - [input^]);
            
            { Prepare `previousCharacter` for _next_ iteration. }
            previousCharacter := input^;
            { Advance “reading cursor”. }
            get(input);
        end;
        
        { To produce POSIX-compliant output write:
        
            writeLn(line:1, ' ', word:1, ' ', character:1);
        
          As per task specification we will determine a common width though.
          We use ⌊ln(N) / ln(10)⌋ + 1 as the base formula, where N needs to be
          the largest number from `line`, `word` and `character`. This can be
          found by the expression |[0, line] ∪ [0, word] ∪ [0, character] ∩ ℤ|.
          We add another +1 for the space _between_ numbers. }
        width := trunc(ln(card([0..line, 0..word, 0..character])) / ln(10)) + 2;
        writeLn(line:width-1, word:width, character:width);
    end.
```
[Answer]
## Ruby, 108 bytes
```
f=->s{a=[s.count($/),s.split(/\S+/).size-1,s.size].map(&:to_s)
a.map{|b|" "*(a.map(&:size).max-b.size)+b}*" "}
```
[Answer]
# Perl, ~~71~~ ~~62~~ 61 bytes
*includes +1 for `-n`*
```
$;=length($b+=y///c);$w+=split$"}{printf"%$;d %$;d $b",$.,$w
```
Commented:
```
while (<>) {                         # implicit because of -n
    $; = length(                     # printf formatting: width
       $b += y///c                   # count characters
    );
    $w += split $"                   # count words
}{                                   # explicit: end while, begin END block
    printf "%$;d %$;d $b", $., $w    #  $. = $INPUT_LINE_NUMBER
}                                    # implicit because of -n
```
* Save another byte, again thanks to @TonHospel.
* Save 9 bytes thanks to @TonHospel showing me a few tricks of the trade!
[Answer]
# Lua, ~~74~~ 66 bytes
Golfed:
```
t=arg[1]_,l=t:gsub('\n','')_,w=t:gsub('%S+','')print(l,w,t:len())
```
Ungolfed:
```
text = arg[1]
_,lines = text:gsub('\n','')
_,words = text:gsub('%S+','')
print(lines, words, text:len())
```
Receives input through command line arguments.
We rename the first argument (`arg[1]`) to save bytes. `string.gsub` returns the number of replacements as well as the modified string, so we're using that to count first `'\n'` (newlines), then `'%S+'` (instances of one or more non-whitespace characters, as many as possible, i.e. words). We can use anything we want for the replacement string, so we use the empty string (`''`) to save bytes. Then we just use `string.len` to find the length of the string, i.e. the number of bytes. Then, finally, we print it all.
[Answer]
# Retina, 65
```
^((\S+)|(¶)|.)*
$#3 $#2 $.0
+`(\b(.)+ )(?!.*\b(?<-2>.)+$)
a$1
a
<space>
```
[Try it Online!](http://retina.tryitonline.net/#code=XigoXFMrKXwowrYpfC4pKgokIzMgJCMyICQuMAorYChcYiguKSsgKSg_IS4qXGIoPzwtMj4uKSskKQphJDEKYQog&input=YWEKCgpiIGMgZCBlIGYgZyBoIGkgaiBrCmwKbQo)
The first stage is the actual wc program, the rest of it is for padding. The `a` placeholder thing is probably unnecessary, and some of the groups can probably be simplified a bit.
[Answer]
# Haskell, 140 bytes
```
import Text.Printf
w h=let{l=length;s=show.l;c=s h;m=s.words$h;n=s.lines$h;f=maximum$map l[c, m, n];p=printf"%*s"f}in p n++' ':p m++' ':p c
```
The ungolfed version is hereunder, with expanded variable and function names:
```
import Text.Printf
wc str =
  let charcount = show.length $ str
      wordcount = show.length.words $ str
      linecount = show.length.lines $ str
      fieldwidth = maximum $ map length [charcount, wordcount, linecount]
      printer = printf "%*s" fieldwidth
  in printer linecount ++ (' ' : printer wordcount ++ (' ' : printer charcount))
```
This is a function that accepts a string and returns a string. It just uses the `Prelude` functions `words` (resp. `lines`) to get the number of words (resp. lines) given that they seem to use the same definition as `wc`, then gets the longest value (as a string) amongst the counts and use the printf format taking the width amongst its arguments for formatting.
[Answer]
# C, 180 178 bytes
```
#include <stdio.h>
#include <ctype.h>
main(b,w,l,c,d){d=' ';b=w=l=0;while((c=fgetc(stdin))!=EOF){if(!isspace(c)&&isspace(d))w++;b++;d=c;if(c==10)l++;}printf("%d %d %d\n",l,w,b);}
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~24~~ 23 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
¨¶¡¹… 
    S¡õK¹)€g§Zg>jJ¦
```
`j` is currently bugged, so could have been 21 bytes without the `§` and `J`..
[Try it online](https://tio.run/##AT4Awf9vc2FiaWX//8KowrbCocK54oCmIAoJU8Khw7VLwrkp4oKsZ8KnWmc@akrCpv//IiIiYQoKCmIKYwpkCiIiIg) or [verify all test cases](https://tio.run/##yy9OTMpM/V9W@f/QikPbDi2sfNSwTIGLM/jQwsNbvSs1HzWtST@0PCrdLsvr0LL/QDmlw/uVdP5HKyUqJCkkK6TE5CnpwNgKqQppYL6CApKIggJETUxeUkxeckxeCowLgihCScmGRsbVtdGxGpp6enpgMahxClAODMI5EFOVYgE).
**Explanation:**
```
¨          # Remove the trailing newline of the (implicit) input
 ¶¡        # And split it on newlines
¹… 
    S¡     # Take the first input again, and split it on [" \n\t"]
      õK   # Then remove all empty string items
¹          # And take the first input again as is
)          # Wrap all three value of the stack to a single list
 €g        # Take the length of each of the items
   §       # Cast the integers to strings (should have been implicit, but `j` is bugged)
    Z      # Take the max (always the last / amount of bytes) (without popping the list)
     g>    # Take the length + 1 of this max
       j   # Append leading spaces so all items or of this length
        J  # Join them together (should have been done by the `j` already, but it's bugged)
         ¦ # Remove the leading space (and output implicitly to STDOUT)
```
[Answer]
# [Ruby](https://www.ruby-lang.org/) `-p0`, 79 bytes
Includes a trailing space in the output.
```
a=[/
/,/\S+/,/./m].map{$_.scan(_1).size}
$_="%#{a.map{_1.to_s.size}.max}d "*3%a
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcnm0km6BgVLsgqWlJWm6Fjf9E22j9bn0dfRjgrWBpJ5-bqxebmJBtUq8XnFyYp5GvKGmXnFmVWotl0q8rZKqcnUiWDreUK8kP74YIgUUqahNUVDSMlZNhBgLNX3BqkQuLq4krmSuFC6ICAA)
## [Ruby](https://www.ruby-lang.org/) `-p0`, 84 bytes
No trailing space.
```
a=[/
/,/\S+/,/./m].map{$_.scan(_1).size}
$_=["%#{a.map{_1.to_s.size}.max}d"]*3*" "%a
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcnm0km6BgVLsgqWlJWm6FjdDEm2j9bn0dfRjgrWBpJ5-bqxebmJBtUq8XnFyYp5GvKGmXnFmVWotl0q8bbSSqnJ1Ilg-3lCvJD--GCIHFKmoTVGK1TLWUlJQUk2EmA21YsGqRC4uriSuZK4ULogIAA)
]