Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • this works! G-man, you are the man. thx Commented Sep 15, 2014 at 18:04
  • @StéphaneChazelas: (1) “Note that you've got no guarantee of order with for (i in max) …” Good point. (2) “That would also cover for columns with only empty fields.” Huh? My current solution handles columns with only empty fields. Commented Sep 15, 2014 at 20:22
  • @StéphaneChazelas: I applied your suggestion, however there is nothing returned. Here is the code, am I making any mistake? awk -F, 'NR!=1 { for (i=1; i<=NF; i++) if (max[i] < length($i)) max[i] = length($i) } END { for (i=1; i<=max_NF; i++) printf "%-2d| %d\n", i, max[i] }' 2014-07-08.csv Commented Sep 15, 2014 at 21:09
  • @QYLuo: You need to add code to set max_NF; see my edit. Commented Sep 15, 2014 at 21:16
  • regarding empty columns, yes, sorry, I had overlooked the fact that accessing max[i] instantiates the array element. Note that length(max) will give you max_NF in GNU awk (but GNU awk only). Commented Sep 15, 2014 at 21:43