Re: Limit on "fmt" buffer size? Loose much of long line.

From: Fred Ma (fma_at_doe.carleton.ca)
Date: 09/15/04

  • Next message: Brian Boutel: "Re: Xah Lee's Unixism"
    Date: 15 Sep 2004 00:30:45 GMT
    
    

    rc wrote:
    >
    > Fred Ma <fma@doe.carleton.ca> wrote in message news:<4144B9AA.F4CCE8D2@doe.carleton.ca>...
    > > UNIX-PROMPT> awk 'BEGIN{RS=" "}{if(length(s)+length()>79){print s;s=$0" "}else
    > > s=s$0" "}END{print s}' < The_File.txt
    >
    > ...Perl can do anything that awk can - and a lot more ; ))
    >
    > The equivalent to the awk one-liner is:
    > perl -ne 'BEGIN{$/="
    > "};if(length($a.$_)>80){print$a."\n";$a=$_}else{$a=$a.$_}'
    >
    > Demonstration:
    >
    > rc@caja:~ $ cat test.txt
    > the goal is to break this line before atmost 80 characters, but only
    > at <whitespace> positions kasdf akjdf adna fasjflkafa, afdnals
    > faln,a,s fksnfa nafn,asnf fnalfan fnalkfansfafnf nlanf f anflalfnlfl
    > allalf a asf asfla afsl falfja f jfj alafal aallfa ajalal.q dsjal blah
    > blah blah
    > rc@caja:~ $
    > rc@caja:~ $ perl -ne 'BEGIN{$/="
    > "};if(length($a.$_)>80){print$a."\n";$a=$_}else{$a = $a.$_}' test.txt
    > the goal is to break this line before atmost 80 characters, but only
    > at
    > <whitespace> positions kasdf akjdf adna fasjflkafa, afdnals faln,a,s
    > fksnfa
    > nafn,asnf fnalfan fnalkfansfafnf nlanf f anflalfnlfl allalf a asf
    > asfla afsl
    >
    > Hope that helps & best regards
    > Christian Ramseyer

    Hi, Christian,

    I tried it on the following 21-line file, then piped it through less.
    It didn't seem to truncate the long lines e.g. line#15, and it seemed
    to put in some empty lines too. Thanks for giving it a crack anyway.

    Fred

    P.S. Line#15 is the long line, so it will probably get truncated in
    this posting.
    ------------------------------------------------------------
         1 MaxWireLen=8
         2 fnStop=MatlabStop
         3 MinBarsTooLong=10
         4 LimlessStart=1000
         5 Initial RndGenr.xseed= 8 40914 54979
         6 DiversityAllPairsEuclidean=0.05559
         7 DiversityCircDiffSimple0.00166189
         8 DiversityCircDiffGoodNorm0.00164503
         9 DiversityCircDiffLinterp0.00494928
        10 GenerationNum:MinViolations
        11 -----------------------------------
        12 50:6
        13 client.mexsol detected stop flag file MatlabStop, iGen=50
        14 [C]ontinue [S]top [K]board: c
        15 100:3 150:2 200:2 250:2 300:1 350:1 400:1 450:1 500:1 550:1 600:1 650:1 700:1 750:1 800:1 850:1 900:1 950:1 1000:1 1050:1 1100:1 1150:1 1200:1 1250:1 1300:1 1350:1 1400:1 1450:1 1500:1 1550:1 1600:1 1650:1 1700:1 1750:1 1800:1 1850:1 1900:1 1950:1 2000:1 2050:1 2100:1 2150:1 2200:1 2250:1 2300:1 2350:1 2400:1 2450:1 2500:1 2550:1 2600:1 2650:1 2700:1 2750:1 2800:1 2850:1 2900:1 2950:1 3000:1 3050:1 3100:1 3150:1 3200:1 3250:1 3300:1 3350:1 3400:1 3450:1 3500:1 3550:1 3600:1 3650:1 3700:1 3750:1 3800:1 3850:1 3900:1 3950:1 4000:1 4050:1 4100:1 4150:1 4200:1 4250:1 4300:1 4350:1 4400:1 4450:1 4500:1 4550:1 4600:1 4650:1 4700:1 4750:1
        16 client.mexsol detected stop flag file MatlabStop, iGen=4750
        17 [C]ontinue [S]top [K]board: s
        18
        19 Elapsed time in evolution loop: 168.641 seconds.
        20 iGen=4750
        21 ifFail=1


  • Next message: Brian Boutel: "Re: Xah Lee's Unixism"