Find the length of the longest line | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Find the length of the longest line

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 ?

Regards,
Pankaj
Sponsored Links
    #2  
Old 11-03-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
 
Join Date: Mar 2005
Last Activity: 5 July 2014, 11:14 AM EDT
Location: classification algos
Posts: 3,203
Thanks: 19
Thanked 30 Times in 27 Posts

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

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 07:57 PM.