Multiple strings, Truncate line at 80 characters

前端 未结 5 844
无人共我
无人共我 2021-02-02 05:57

I\'m new to awk and sed, and I\'m looking for a way to truncate a line at 80 characters, but I\'m printing several strings in that line using printf. The last two strings are th

5条回答
  •  野性不改
    2021-02-02 06:25

    Another way to solve this just using Bash (syntax: ${var:0:80}), e.g.:

    printf "%5d  %3s%.2s %4s %s %s \n" "$f" "$month" "$day" "$year" "$from" "${subject::80}"
    

    This truncates the string before it gets to printf. This method would also allow you to specify different maximum widths for each printed column individually.

提交回复
热议问题