It is currently Thu, 20 Jan 2022 05:14:49 GMT



 
Author Message
 find length longest line in a file
Hi,

This is probably easy but its puzzling me at the moment.  I want to
find how long the longest line in a file is in characters.

  /Dave



 Mon, 10 Nov 2003 20:15:20 GMT   
 find length longest line in a file
In article <5d97e199.0105240415.736f...@posting.google.com>,

awk 'length > l {l = length} END{print l + 1}' infile

Chuck Demas

--
  Eat Healthy    |   _ _   | Nothing would be done at all,
  Stay Fit       |   @ @   | If a man waited to do it so well,
  Die Anyway     |    v    | That no one could find fault with it.
  de...@tiac.net |  \___/  | http://www.tiac.net/users/demas



 Mon, 10 Nov 2003 20:47:47 GMT   
 find length longest line in a file

There is no need to puzzle, "info wc", it's the --max-line-length
option.

Michael Heiming



 Mon, 10 Nov 2003 21:41:49 GMT   
 find length longest line in a file

wc on hpux doesn't have a -max-line-length option.



 Mon, 10 Nov 2003 21:58:42 GMT   
 find length longest line in a file

Hello Chuck,

your line outputs one more sign then "wc --max-line-length infile"?

However, it's much easier to output the line & number of signs, using
awk...:-)

awk 'length > l{l=length;ll=$0}END{print ll" "l}' infile

Regards

Michael Heiming



 Mon, 10 Nov 2003 22:12:42 GMT   
 find length longest line in a file

OK, perhaps the nice line awk Chuck suggest doesn't work with the
awk_we_don't_know(tm) the OP uses on his we_don't_know(tm)system, too?

It would be better if the OP had included which system he uses.

However, all of the well written GNU tools, can be downloaded
for free and compiled without many problems on almost every UNIX
system...:-)

Regards

Michael Heiming



 Mon, 10 Nov 2003 23:04:43 GMT   
 find length longest line in a file
In article <3B0D16DA.166A4...@heiming.de>,
Michael Heiming  <mich...@heiming.de> wrote:

I added 1 to account for the newline.

Chuck Demas

--
  Eat Healthy    |   _ _   | Nothing would be done at all,
  Stay Fit       |   @ @   | If a man waited to do it so well,
  Die Anyway     |    v    | That no one could find fault with it.
  de...@tiac.net |  \___/  | http://www.tiac.net/users/demas



 Tue, 11 Nov 2003 00:20:15 GMT   
 find length longest line in a file

he's right and you're wrong. here, we try to speak portable.
read, what could be supported by almost every systems.

of course, GNU tools could be installed on almost every systems, but
they don't for whatever reason.

it would be really better that you say *GNU* wc support whatever
option and not just, of course, RTFM, wc has such option which didn't
exist on almost systems.

so, your mind is so restricted that you couldn't do anything w/o
whatever GNU tools ?

what's happen the day you'll have to work somewhere where GNU tools
aren't installed. you're dead. of course, you can says, he, guys,
how can you work w/o GNU tools, and they can answer to you, he, guy,
if you didn't know how to work w/o them, you can't work here.

Cyrille.
--
home: mailto:clefevre%no-s...@redirect.to.invalid    | UNIX is user-friendly;
work: mailto:Cyrille.Lefevre%no-s...@edf.fr.invalid  | it's just particular
Supprimer "%no-spam" et ".invalid" pour me repondre. | about who it chooses
Remove "%no-spam" and ".invalid" to answer me back.  | to be friends with.



 Tue, 11 Nov 2003 11:35:00 GMT   
 find length longest line in a file

OK, that's a good point.
And something I'll try to remember in the future...:-)

It's not, but why should I waste my time with inferior tools?

That's clearly an advantage of being UID 0.
However, I wouldn't work on a place I'm not allowed to use the tools, I
like.

Michael Heiming



 Tue, 11 Nov 2003 14:16:47 GMT   
 find length longest line in a file

who says ? for security reasons or whatever... :P

Cyrille.
--
home: mailto:clefevre%no-s...@redirect.to.invalid    | UNIX is user-friendly;
work: mailto:Cyrille.Lefevre%no-s...@edf.fr.invalid  | it's just particular
Supprimer "%no-spam" et ".invalid" pour me repondre. | about who it chooses
Remove "%no-spam" and ".invalid" to answer me back.  | to be friends with.



 Tue, 11 Nov 2003 14:39:59 GMT   
 find length longest line in a file

I have worked in environments (e.g. banking) where you were limitted in what you
used to what was on the system for security reasons.  There are times as well
that you may be able to install the tools you need on your own system at work but
if the tool is needed at other sites then there is no guaranty that your
installed utilities will be there or the version that you expect.



 Tue, 11 Nov 2003 21:38:51 GMT   
 
   [ 11 post ] 

Similar Threads

1. a SED script to find length of the longest line in a file

2. long line length causes grep crash

3. Getting line lengths from a file

4. Group File Line Length Exceeded

5. Lengths of the sequences of common lines in two files

6. .htgroup files and max line length

7. Line Length Limit in Netgroup file?

8. How to find out all the input args of a long command line

9. How to find a file of given length?

10. Finding the length of a file.


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software