Walt Stoneburner's Ramblings

Currating Chaos

Longest Line with wc on macOS

The version of wc that comes with macOS doesn't provide the -L option that provides the length of the longest line.

Upgrading or changing tools provided by Apple's operating systems tend to break other pieces of the operating system in strange ways or cause integrity problems when upgrading the operating system. Best not to do that.

Instead, work in a sandbox. And as it turns out, Homebrew does just that.

The GNU version of wc would be a naming collision (as would other utilities), so Homebrew lets the GNU utilities install with a g prefix. The GNU utilities reside in the coreutils package.

Install like so:

$ brew update
$ brew upgrade
$ brew install coreutils

Then use the gwc utility like so to show the longest line in a file:

$ gwc -L filename