mju@mudos.ann-arbor.mi.us (Marc Unangst) (02/19/91)
In article <1991Feb18.205238.14418@dartvax.dartmouth.edu> mdm@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 -- Marc Unangst | "I think I have a bad disk. Even though I mju@mudos.ann-arbor.mi.us | folded it to fit into my drive, it still ...!umich!leebai!mudos!mju | doesn't work..." -Caller to a tech support line
tchrist@convex.COM (Tom Christiansen) (02/19/91)
From the keyboard of mdm@icefloe.dartmouth.edu (Michael McDaniel): :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 :characters, and I know that there is some way to get awk to do it, but I :can't remember how to do it. #!/bin/awk -f print substr($0,1,80) Somebody should buy that guy a manual for Christmas. --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "All things are possible, but not all expedient." (in life, UNIX, and perl)
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (02/20/91)
In article <1991Feb19.014649.133@mudos.ann-arbor.mi.us> mju@mudos.ann-arbor.mi.us (Marc Unangst) writes: : In article <1991Feb18.205238.14418@dartvax.dartmouth.edu> mdm@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@jpl-devvax.jpl.nasa.gov
brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (02/20/91)
In article <11500@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
[ examples of fixed limits in cut and awk ]
colrm 81.
Hell, my colrm clone runs three times faster than Perl on this one,
partly because it avoids stdio, partly bec... oops, not s'posed to talk
about efficiency when you've already got 'em slaughtered on syntax.
[grin]
---Dan