Using Raku (formerly known as Perl_6)
~$ raku -ne 'BEGIN my @a; unless ++$ == 1 { @a.push: $_.split(",").map: *.chars; }; END say( ++$ ~ " | " ~ $_ ) for ([Z] @a).map: *.max;' fileOR:
~$ raku -ne 'BEGIN my @a; once next; @a.push: $_.split(",").map: *.chars; END say( ++$ ~ " | " ~ $_ ) for ([Z] @a).map: *.max;' fileHere's an answer coded in Raku, a member of the Perl-family of programming languages. Raku features high level support for Unicode, so that character-counting is accurate.
We start by using the (awk-like) -ne linewise non-autoprinting command line flags:
- An array is declared in a
BEGINblock, - To remove the header-line (first answer), an anonymous counter (
++$) is used to skip the first line. Alternatively (second answer),once nextcan be used, - Within the body of the block/loop, each line is read-in,
spliton commas, and each resultant element ismapped into to obtain the number ofchars(characters). These are pushed onto@aarray, - After all lines are read-in, the
ENDblock executes. The@aarray is[Z]transformed such that rows and columns are interchanged. Once this happens we can thenmapinto elements at each array position, and obtain themax. Finally the data is output, using an++$anonymous counter to provide line-numbers (string-concatenation is accomplished with~tilde).
Sample Input:
These,are,the,column_headings_which_may_be_very_long_but_they_don't_countabcdefghij,abcdefghijk,abcdefghijkl,abcaardvark,bat,cat,dogant,bee,cow,abcdefghijklmSample Output:
1 | 102 | 113 | 124 | 13Note: There's no error-checking on number-of-columns per line: the [Z] transform will simply truncate rows with an excessive number to the common (i.e. to 4 columns in the example). See the first link below to accomplish this task in Raku regardless of the number of columns per line.
https://unix.stackexchange.com/a/774828/227738
https://docs.raku.org/language/unicode
https://raku.org