rpjday <[EMAIL PROTECTED]> wrote:

>On Thu, 31 Aug 2000, Eric Sisler wrote:
>
> > Ok, stupid question of the day.
> >
> > I'm trying to find & print (dump to a file) the longest line in a text
> > file.  I've been able to determine the *length* of the longest line by
> > using the 'wc -L' command, but is there any way using find or some other
> > command to *output* the longest line?

>ah, way too easy.
>
>maxlen=$(wc -L filename)
>grep "^.\{$maxlen\}$" filename
>
>note that this prints *all* lines of the max length.

Not quite, but close enough to point me in the right direction.  ;-)

I had to use egrep instead of grep and although the "maxlen" variable is a 
neat idea, wc puts the filename at the end of the results, so the value of 
"maxlen" wound up being "2096722 adcontroller.txt".  Oh well, simple enough 
to just plug the number into grep's regular expression, once I figured out 
what you were doing with it.  I've been reading "mastering regular 
expressions" but apparently haven't gotten to using {}'s yet.  (That or it 
didn't sink in.)  I think my biggest problem now will be the length of the 
line in question (2,096,772 chars) and the sheer size of the file 
(~314Mb).  I may see if re-arranging the regex helps speed thing up a bit.

Thanks for pointing me in the right direction - I thought their *must* be a 
way to do it with grep (rather than find which I initially wrote by 
mistake), I just didn't have the syntax.  Time to read more of the regular 
expressions book.

-Eric


Eric Sisler
Library Computer Technician
Westminster Public Library
Westminster, CO, USA
[EMAIL PROTECTED]

Linux - don't fear the Penguin.
Want to know what we use Linux for?
Visit http://gromit.westminster.lib.co.us/linux



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to