Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何包装来自grep的长结果_Bash_Word Wrap_Uniq - Fatal编程技术网

Bash 如何包装来自grep的长结果

Bash 如何包装来自grep的长结果,bash,word-wrap,uniq,Bash,Word Wrap,Uniq,请原谅我的无知。我是Unix的新手。这听起来可能很傻。 我正在一个包含一些日志详细信息的文件上运行下面的命令 目录/日志文件| uniq-c 现在,当文件包含超出屏幕宽度的超长行时,它会在文本查看器上为用户创建一个水平滚动条 是否有什么方法可以将文本换行到下一行,以便结果对用户来说清晰易读、滚动友好?下面看起来像的东西 23 This is just a sample result text that has come up to be very long but was WRAPP

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

目录/日志文件| uniq-c

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

是否有什么方法可以将文本换行到下一行,以便结果对用户来说清晰易读、滚动友好?下面看起来像的东西

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? 23这只是一个示例结果文本,虽然很长,但是 包装到下一行,以便结果显示在滚动fri中 endly格式。这真的有可能吗?
你在用什么终端?你在哪里看到这些滚动条

通常,输出应按预期进行换行,但换行的行从行的开头开始,而不是对齐,因此我希望您从命令中获得以下输出:

 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

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

通常,输出应按预期进行换行,但换行的行从行的开头开始,而不是对齐,因此我希望您从命令中获得以下输出:

 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

您可以使用
折叠
实用程序,例如:

$ 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?

您可以使用
折叠
实用程序,例如:

$ 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?

我不会在终点站面对这个。为了便于报告,我将输出定向到文本文件。因此,当文本文件打开时,内容不会被包装。当然,我可以在文本板中使用换行选项,但要求是将一行中的字符数限制为一个固定的数字,并以正确的对正方式开始下一行,使其看起来像一个表格布局。我认为Adrian建议的
fold
应该可以做到这一点,但您需要以正确的顺序传递命令。我已经用例子编辑了我的答案。我认为你是在现场,我不认为OP可能在“错误”的命令中。我不是在终端上面对这个。为了便于报告,我将输出定向到文本文件。因此,当文本文件打开时,内容不会被包装。当然,我可以在文本板中使用换行选项,但要求是将一行中的字符数限制为一个固定的数字,并以正确的对正方式开始下一行,使其看起来像一个表格布局。我认为Adrian建议的
fold
应该可以做到这一点,但您需要以正确的顺序传递命令。我已经用例子编辑了我的答案。我认为你是在那里,我不认为OP可能在错误的顺序中。我以前使用过这个,但是这对我的要求没有帮助。由于折叠将长线分割成单独的部分,uniq-c失去了它的作用。它最终会获取完全拆分的唯一行。我试图实现的是包装“cat text | uniq-c”的文本结果。我相信您只是按照错误的顺序进行了配管,您需要将
fold
应用为管道中的最后一个命令,例如
uniq-c./Logfile | fold-s-w 80
cat
,顺便说一句。).我以前用过这个,但对我的要求没有帮助。由于折叠将长线分割成单独的部分,uniq-c失去了它的作用。它最终会获取完全拆分的唯一行。我试图实现的是包装“cat text | uniq-c”的文本结果。我相信您只是按照错误的顺序排列,您需要将
fold
应用为管道中的最后一个命令,例如
uniq-c./Logfile | fold-s-w 80
cat
,顺便说一句)。