How to truncate STDIN line length?

前端 未结 9 1838
醉酒成梦
醉酒成梦 2021-01-05 07:15

I\'ve been parsing through some log files and I\'ve found that some of the lines are too long to display on one line so Terminal.app kindly wraps them onto the next line. Ho

9条回答
  •  灰色年华
    2021-01-05 07:33

    Unless I'm missing the point, the UNIX "fold" command was designed to do exactly that:

    $ cat file
    the quick brown fox jumped over the lazy dog's back
    
    $ fold -w20 file
    the quick brown fox
    jumped over the lazy
     dog's back
    
    $ fold -w10 file
    the quick
    brown fox
    jumped ove
    r the lazy
     dog's bac
    k
    
    $ fold -s -w10 file
    the quick
    brown fox
    jumped
    over the
    lazy
    dog's back
    

提交回复
热议问题