Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-03-2007
Registered User
 
Join Date: Apr 2007
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
Technorati Master
 
Join Date: Mar 2005
Location: classification algos
Posts: 3,188
Thanks: 19
Thanked 28 Times in 25 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 05:51 PM.