how to truncate lines

Larry Wall lwall at jpl-devvax.JPL.NASA.GOV
Wed Feb 20 09:19:47 AEST 1991


In article <1991Feb19.014649.133 at mudos.ann-arbor.mi.us> mju at mudos.ann-arbor.mi.us (Marc Unangst) writes:
: In article <1991Feb18.205238.14418 at dartvax.dartmouth.edu> mdm at icefloe.dartmouth.edu (Michael McDaniel) writes:
: >I am trying to write a simple shell script that will truncate lines fed
: >from the standard input to 80 characters.  I only want the first 80
: 
: cat file.with.really.long.lines | cut -c1-80 > file.with.shorter.lines

perl -e 'print "*" x 1023, "\n"' | cut -c1-80
cut: ERROR: line too long

perl -e 'print "*" x 2560, "\n"' | awk '{print substr($0,1,80)}'
awk: record `********************...' too long

perl -e 'print "*" x 1_000_000, "\n"' | perl -pe 'chop; $_=substr($_,0,80)."\n"'
********************************************************************************

Larry Wall
lwall at jpl-devvax.jpl.nasa.gov



More information about the Comp.unix.programmer mailing list