使用 bash 缩小文件中的文本

使用 bash 缩小文件中的文本

我的文本文件如下所示:

If you are a software developer in your 20s or 30s, you've grown up in a world dominated by Linux. It has been a significant player in the data center for decades, and while it's hard to find definitive operating system market share reports, Linux's share of data center operating systems could be as high as 70%, with Windows variants carrying nearly all the remaining percentage. Developers using any major public cloud can expect the target system will run Linux. Evidence that Linux is everywhere has grown in recent years when you add in Android and Linux-based embedded systems in smartphones, TVs, automobiles, and many other devices.

我想缩小它,使它看起来像这样

If you are a software developer in your 20s or 30s, 
you've grown up in a world dominated by Linux. It ha
s been a significant player in the data center for d
ecades, and while it's hard to find definitive opera
ting system market share reports, Linux's share of d
ata center operating systems could be as high as 70%
, with Windows variants carrying nearly all the rema
ining percentage. Developers using any major public 
cloud can expect the target system will run Linux. E
vidence that Linux is everywhere has grown in recent
 years when you add in Android and Linux-based embed
ded systems in smartphones, TVs, automobiles, and ma
ny other devices.

然后将其放大,使其看起来像这样:

If you are a software developer in your 20s or 30s, you've grown up in a world dominated by Linux. It has been a significant player in the data center for decades, and while it's hard to find definiti
ve operating system market share reports, Linux's share of data center operating systems could be as high as 70%, with Windows variants carrying nearly all the remaining percentage. Developers using a
ny major public cloud can expect the target system will run Linux. Evidence that Linux is everywhere has grown in recent years when you add in Android and Linux-based embedded systems in smartphones, 
TVs, automobiles, and many other devices.

我该怎么做,我需要将其包含在我的脚本中

答案1

你可以使用命令折叠如下:

fold -w 

命令折叠中的标志w可以根据包含的列数控制文本(收缩与扩展)。

在你的例子中:

fold -w 52 file 

fold -w 200 file

答案2

您可以使用此命令:

sed 's/.\{80\}/&\n/g' file

其中80是您想要在一行中包含的字符数,file是您存储文本的文件。

.\{80\}- 正则表达式精确匹配 80 个字符

&\n- 附加\n到匹配的文本

相关内容