多个字符串,在80个字符截断线 [英] Multiple strings, Truncate line at 80 characters

查看:124
本文介绍了多个字符串,在80个字符截断线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的awk和sed,我期待一种可以截断在80个字符的行,但我用printf打印几串在该行。最后两个字符串是给我的问题,因为它们大小不等我的code的每一次迭代的人。这是我目前的code:

 的printf%5D%三分%.2s%4S%s%S \\ n$ F,每月$$日$年从$ $主题

这code是被用来创建打通一个Bash脚本通过电子邮件的摘要。我所知道的是,与我的其他琴弦的空间和要求,我有房价格从$主题字符串$ 60之间的字符和

任何帮助是AP preciated。


解决方案

  

我在寻找一种方式在80个字符截断行...


您可以管道输出到剪切

 的printf ... |切-c 1-80


如果你想确保每行不超过80个字符(或换行以适合指定的宽度),你可以使用折叠

 的printf ... |折叠-w 80

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 the ones that give me problems because they vary in size on each iteration of my code. Here's my current code:

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

This code is being used to create a summary of email messages that get passed through a Bash script. What I do know, is that with the spaces and requirements of my other strings, I have room for 60 characters between the $from and $subject strings.

Any help is appreciated.

解决方案

I'm looking for a way to truncate a line at 80 characters ...

You could pipe the output to cut:

printf ... | cut -c 1-80


If you wanted to ensure that each line isn't more than 80 characters (or wrap lines to fit in specified width), you could use fold:

printf ... | fold -w 80

这篇关于多个字符串,在80个字符截断线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆