Computing.Net > Forums > Unix > Max column count in AIX

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Max column count in AIX

Reply to Message Icon

Name: hisharme
Date: November 3, 2007 at 02:27:35 Pacific
OS: AIX
CPU/Ram: 2GB
Comment:

Hi,

I need to find max column lenth of each column in a file. for eg. if file has
col1 col2 col3
xyz abc mnopq
ab pq xx

The output i need as col 1: 3, col2 :3 , col3 :4

please help, as in linux we can use wc -L but in UNIX AIX i couldn't find any command.

Any help would be appreciated, thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: fpmurphy
Date: November 4, 2007 at 05:45:10 Pacific
Reply:

I am confused. In the GNU/Linux wc utility the
-L (--max-line-length) argument prints the length of the longest line - not the length of the maximum column.


0

Response Number 2
Name: James Boothe
Date: November 7, 2007 at 12:44:48 Pacific
Reply:

When the array entries are printed in the END statement, they often will not come out in numerical column order. But a little additional code can resolve that.

awk '{
for (i=1; i<=NF; i++)
   if ( length($i)>column[i] )
       column[i]=length($i)
}
END {
for (i in column)
    print i, column[i]
}' infile


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Max column count in AIX

Max column count in a file www.computing.net/answers/unix/max-column-count-in-a-file-/6444.html

Displaying date-7 in AIX www.computing.net/answers/unix/displaying-date7-in-aix/7691.html

Change IP address in AIX www.computing.net/answers/unix/change-ip-address-in-aix/4134.html