我有以下数据,我需要将其全部放在格式段落中。
Don Quixote has inspired many artists
in different fields. It is considered mainly to
be a comedy. However, woven into the tale is a lot of Spain's
history. Don Quixote's name even penned a type of psychosis.
In fact, anyone who has had experience with the mentally ill
may find it difficult to regard Don Quixote as a comedy. After
all, he was not totally harmless.
"A man attacked a driver because he believed he was abducting a
woman, who was traveling in another car on the same road.
After injuring the driver, the suspect's accomplice then
forced the driver to remove his clothes and give them to
him"--if this was reported on the news, we would probably
e horrified. Here was an innocent person, just going about
his business, who had no connection to the other people who
were on the same road--and he gets attacked by a madman
whose delusions cause him to believe a different reality.
我需要这个:
堂吉诃德激励了许多不同领域的艺术家。它被认为主要是喜剧。然而,编入故事是西班牙很多历史。唐吉诃德的名字甚至写了一种精神病。
事实上,任何有过精神病患者经验的人都会觉得很难将唐吉诃德视为一部喜剧。毕竟,他并非完全无害。
"一名男子袭击了一名司机,因为他相信他绑架的是一名女子,她正乘同一条路上的另一辆车旅行。
在打伤司机后,犯罪嫌疑人的帮凶然后强迫司机脱掉他的衣服并将他们交给他......如果有新闻报道,我们会可能会感到恐惧。这是一个无辜的人,只是为了他的生意,与同一条路上的其他人没有关系 - 他被一个疯子殴打,他的妄想使他相信不同的现实。 的
答案 0 :(得分:1)
注意:假设是你想:
有几个选项:
使用fmt
作为user1934428's answer建议,无限行长度:
fmt
需要特定的数字作为目标行长度,而 GNU fmt
(至少从coreutils v8.24开始),该值的上限为2500
,可能不够大,具体取决于您的需求:fmt -w 2500 file
。fmt
显然接受任意大数字,但我不知道它在实践中被切断了。使用awk
,如下所示。
如果您安装了whitespace-normalizing nws
CLI,则可以使用nws --fp file
awk
解决方案:
awk -v RS= '
BEGIN { OFS=" "; ORS="\n\n" }
NR > 1 { print "" }
{ $1 = $1; printf "%s", $0 }
END { printf "\n" }
' file
-v RS=
,即将输入记录分隔符设置为空字符串,是一种Awk习惯用法,它使Awk考虑连续的非空行 - 段落 - 单个记录。
OFS=" "
将output- 字段分隔符设置为单个空格。
ORS="\n\n"
将output- 记录分隔符设置为2个换行符。
$1 = $1
是一种强制重建输入记录的技巧,它通过将OFS
加入字段(通过任何空白行分割获得)来获取,在这种情况下用空间有效地替换每个块内部换行符; printf "%s", $0
首先打印重建的行而不使用 ORS(见下文)。
NR > 1 { print "" }
延迟将ORS打印一行,以便最后不会自动打印ORS,这将导致 2 尾随\n
个字符。在{ printf "\n" }
区块中END
,然后打印单个尾随\n
。
答案 1 :(得分:1)
不是
fmt file
做你想要达到的目标?