Berkeley CSUA MOTD:Entry 11304
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/07/08 [General] UID:1000 Activity:popular
7/8     

2003/12/3 [Computer/SW/Languages/Perl] UID:11304 Activity:very high
12/2    What's a quick way to find the length of the longest line in a file?
        \_ perl -p -e'print length $_; s/.*//' <file> |sort -n|tail -1
           \_ perl -pe 's/.*/length/e'
           \_ perl -pe 's/.*/length $_/e'
           \_ perl -lpe '$_=length'
              however this automatically chomps the trailing newline, so
              you'll need to add 1 to the result if you care about them.
              -geordan
                \_ what does the l do? which perldoc describes cmdline args?
                   \_ man perlrun
           \_ awk '{print length}'
        \_ awk '{L=L>length?L:length}END{print L}' <FILE>
           \_ perl -pe 's/.*/length $_/e'
              -geordan
           no sort or tail needed. beat that!