Reduzindo texto em um arquivo usando bash [duplicate]

0

Eu tenho um arquivo de texto com esta aparência:

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.

eu quero encolher para que pareça com isso

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.

e, em seguida, amplie-o para que fique assim:

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.

como posso fazer isso, preciso incluir isso no meu script

    
por David Foerster 09.10.2018 / 16:34

2 respostas

6

Você pode usar o comando fold da seguinte forma:

fold -w 

O sinalizador w na dobra de comandos pode controlar o texto (encolher vs estender) dependendo do número de colunas incluídas.

No seu exemplo:

fold -w 52 file 

e

fold -w 200 file
    
por 09.10.2018 / 16:39
3

Você pode usar este comando:

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

Em que 80 é o número de caracteres que você deseja ter em uma linha e file é o arquivo em que você armazena seu texto.

.\{80\} - regexp que corresponde exatamente a 80 caracteres

&\n - anexar \n ao texto correspondente

    
por 09.10.2018 / 16:45