0

请原谅我的无知。我是 Unix 的新手。这听起来可能很愚蠢。我正在对包含一些日志详细信息的文件运行以下命令。

cat ./日志文件 | 唯一的-c

现在,当文件包含超出屏幕宽度的超长行时,它会在文本查看器上为用户创建一个水平滚动条。

有没有办法可以将文本换行到下一行,以便结果看起来清晰易读并且对用户滚动友好?看起来像下面的东西。

23 这只是一个示例结果文本,它很长,但
    WRAPPED 到下一行,以便结果以滚动条的形式显示
    最终格式。这真的可能吗?
4

2 回答 2

2

您可以使用该fold实用程序,例如:

$ cat text
This is just a sample result text that has come up to be very long but was WRAPPED to the next line so that the results are displayed in a scroll friendly format. Is that really possible?

$ fold -s -w 80 text
This is just a sample result text that has come up to be very long but was
WRAPPED to the next line so that the results are displayed in a scroll friendly
format. Is that really possible?
于 2013-05-11T14:56:14.973 回答
1

你用的是什么终端?您在哪里看到这些滚动条?

通常,输出应该按照您的预期换行,除了换行从行首开始而不是对齐,所以我希望您从命令中获得以下输出:

 23  This is just a sample result text that has come up to be very long but was 
WRAPPED to the next line so that the results are displayed in a scroll fri
endly format. Is that really possible?

编辑:感谢您的澄清,现在我了解您的情况。我想你可以像其他人在这里建议的那样使用这个折叠,但是在 uniq 之后管道它:

cat ./Logfile | uniq -c | fold -s -w 80 > result.txt
于 2013-05-11T14:07:26.753 回答