目前,我正在设法使用cat命令将文本文件显示为我正在执行的项目的自动编号段落,但我没有找到一个命令。
示例:
Frederick II (German: Friedrich; 24 January 1712 – 17 August 1786) was King of Prussia from 1740 until 1786.[1] His most significant accomplishments during his reign included his military victories, his reorganization of Prussian armies, his patronage of the Arts and the Enlightenment in Prussia, and his final success against great odds in the Seven Years' War.
Frederick was the last titled King in Prussia and declared himself King of Prussia after achieving full sovereignty for all historical Prussian lands. Prussia had greatly increased its territories and became a leading military power in Europe under his rule. He became known as Frederick the Great (Friedrich der Große) and was affectionately nicknamed Der Alte Fritz ("Old Fritz") by the Prussian people.然后,一旦输入了命令:
1. Frederick II (German: Friedrich; 24 January 1712 – 17 August 1786) was King of Prussia from 1740 until 1786.[1] His most significant accomplishments during his reign included his military victories, his reorganization of Prussian armies, his patronage of the Arts and the Enlightenment in Prussia, and his final success against great odds in the Seven Years' War.
2.Frederick was the last titled King in Prussia and declared himself King of Prussia after achieving full sovereignty for all historical Prussian lands. Prussia had greatly increased its territories and became a leading military power in Europe under his rule. He became known as Frederick the Great (Friedrich der Große) and was affectionately nicknamed Der Alte Fritz ("Old Fritz") by the Prussian people.这是我真诚地认为我会很容易找到的东西,但我还没有找到一个网站的答案,如何做到这一点。(请记住,它必须是cat命令的变体。)
发布于 2016-09-08 13:44:19
在你的例子中,每一段实际上只是一行。将其形成一个段落的唯一方法是在用于显示它的任何应用程序中使用文本包装。
可以使用cat对文件中的所有非空行进行编号:
cat -b file如果要将此文件发送到另一个文件,请使用重定向:
cat -b file > newfileman命令对于学习其他命令的使用非常有用,例如man cat给出:
NAME
cat - concatenate files and print on the standard output
SYNOPSIS
cat [OPTION]... [FILE]...
DESCRIPTION
Concatenate FILE(s), or standard input, to standard output.
-A, --show-all
equivalent to -vET
-b, --number-nonblank
number nonempty output lines, overrides -n
-e equivalent to -vE
-E, --show-ends
display $ at end of each line
-n, --number
number all output lines
-s, --squeeze-blank
suppress repeated empty output lines
-t equivalent to -vT
-T, --show-tabs
display TAB characters as ^I
-u (ignored)
-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB
--help display this help and exit
--version
output version information and exit
With no FILE, or when FILE is -, read standard input.
EXAMPLES
cat f - g
Output f's contents, then standard input, then g's contents.
cat Copy standard input to standard output.
AUTHOR
Written by Torbjorn Granlund and Richard M. Stallman.
REPORTING BUGS
Report cat bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
Report cat translation bugs to <http://translationproject.org/team/>
COPYRIGHT
Copyright © 2013 Free Software Foundation, Inc. License GPLv3+: GNU
GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
tac(1)
The full documentation for cat is maintained as a Texinfo manual. If
the info and cat programs are properly installed at your site, the
command
info coreutils 'cat invocation'
should give you access to the complete manual.发布于 2016-09-08 21:08:45
“段落”还不是段落,只是长队(正如其他人所指出的)。
我们需要对这些行进行编号,然后将它们写成段落,您可以使用折叠。
cat -b file | fold -sw 80这个数字的非空行,管道到折叠,使宽度保持在80个字符(或列),并打破了线上的空格。
Frederick II (German: Friedrich; 24 January 1712 – 17 August 1786) was King of Prussia from 1740 until 1786.[1] His most significant accomplishments during his reign included his military victories, his reorganization of Prussian armies, his patronage of the Arts and the Enlightenment in Prussia, and his final success against great odds in the Seven Years' War.
Frederick was the last titled King in Prussia and declared himself King of Prussia after achieving full sovereignty for all historical Prussian lands. Prussia had greatly increased its territories and became a leading military power in Europe under his rule. He became known as Frederick the Great (Friedrich der Große) and was affectionately nicknamed Der Alte Fritz ("Old Fritz") by the Prussian people.
1 Frederick II (German: Friedrich; 24 January 1712 – 17 August 1786)
was King of Prussia from 1740 until 1786.[1] His most significant
accomplishments during his reign included his military victories, his
reorganization of Prussian armies, his patronage of the Arts and the
Enlightenment in Prussia, and his final success against great odds in the Seven
Years' War.
2 Frederick was the last titled King in Prussia and declared himself King
of Prussia after achieving full sovereignty for all historical Prussian lands.
Prussia had greatly increased its territories and became a leading military
power in Europe under his rule. He became known as Frederick the Great
(Friedrich der Große) and was affectionately nicknamed Der Alte Fritz ("Old
Fritz") by the Prussian people. -b, --number-nonblank
number nonempty output lines, overrides -n -s, --spaces
break at spaces
-w, --width=WIDTH
use WIDTH columns instead of 80发布于 2017-01-13 14:56:33
我不知道“段落”命令。cat -b是您想要使用的。
假设这是今年的一项具体的受控评估任务;)行号和段落编号之间的混淆可能源于这样一个事实:如果您使用pico/nano使文本文件看起来像一个段落,在编写内容时按enter键可以使它看起来像一个段落,因此您的每个“段落”都只是一行。
尝试在具有word包装的桌面环境中的测试编辑器中生成该文件。您将看到cat -b输出看起来与您预期的一样。命令行编辑器中的段落只是一行很长的文本,不带文字包装。
https://askubuntu.com/questions/822527
复制相似问题