Created
February 19, 2016 08:34
-
-
Save rohitprajapati/6d8535705898a082e259 to your computer and use it in GitHub Desktop.
Given a csv file with header. Find the max size(character length) required for each column.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: awk -f max_column_size.awk ~/Desktop/test.csv | |
# csv header required | |
BEGIN { | |
FS="," | |
OFS="," | |
} | |
NR == 1 { | |
for(n = 1; n <= NF; n++) { | |
colname[n]=$n | |
} | |
} | |
NR > 1 { | |
for(n = 1; n <= NF; n++) { | |
if (length($n)>maxlen[n]) | |
maxlen[n]=length($n) | |
} | |
} | |
END { | |
for(i = 1; i <= NF; i++) { | |
print colname[i], ":", maxlen[i]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment