Berkeley CSUA MOTD:Entry 28349
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/25 [General] UID:1000 Activity:popular
5/25    

2003/5/6-7 [Computer/SW/Languages/Perl] UID:28349 Activity:high
5/6     How do I use sed to truncate output lines to say 60char/columns?
        \- helo "man cut" ok tnx. --psb
           \_ command | cut -c1-60
              \_ will truncate, yes, but not useful for wrapping the text.
                 \_ Was text-wrapping requested? No.
                 \_ Um.. if you wanted line wrapping, use fmt.
        \_ perl is the answer to all text modifying or extraction questions.
           \_ Ok fine.  How do I do this in perl?
              \_ command | perl -n -e 'print substr $_,0,60,"\n";' though
                 I suspect this would be trivial with sed.--scotsman
              \_ command | perl -pe 's/^(.{1,60}).*$/\1/;'
        \_ Try "fold".
        \_ Try "fmt".
        \_ Try ED! and counting out to the 60th character on each line and
           deleting everything after it.  Save the file out to a different
           file name if you need the original.