Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Find the length of the longest line

Shell Programming and Scripting

Thread Tools Search this Thread Display Modes
Old Unix and Linux 11-03-2007
panknil panknil is offline
Registered User
Join Date: Apr 2007
Last Activity: 19 February 2013, 12:36 PM EST
Location: Kolkata
Posts: 90
Thanks: 2
Thanked 0 Times in 0 Posts
Find the length of the longest line

Dear All,

To find the length of the longest line from a file i have used wc -L which is giving the proper output...

But the problem is AIX os does not support wc -L command.
so is there any other way 2 to find out the length of the longest line using awk or sed ?

Sponsored Links
Old Unix and Linux 11-03-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
Join Date: Mar 2005
Last Activity: 10 January 2017, 8:10 AM EST
Location: classification algos
Posts: 3,215
Thanks: 19
Thanked 31 Times in 28 Posts

awk ' { if ( length > x ) { x = length } }END{ print x }' filename

Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Longest length of string in array mmab Shell Programming and Scripting 12 12-14-2011 12:14 PM
Display all the words whose length is equal to the longest word in the text bawse.c UNIX for Dummies Questions & Answers 4 08-14-2011 06:32 AM
Find longest string and print it SEinT Shell Programming and Scripting 6 04-20-2011 07:39 AM
Find the length of each line in the file Suryaaravindh Shell Programming and Scripting 7 02-26-2011 07:38 AM
Bash script find longest line/lines in several files 1tempus1 Shell Programming and Scripting 23 10-27-2010 12:33 PM

All times are GMT -4. The time now is 06:50 PM.