0

I have text file look like this:

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.

i want to shrink it so it look like this

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.

and then enlarge it so it look like this:

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.

how can I do that, i need to include that in my script

2 Answers2

6

You can use the command fold as follows:

fold -w 

The flag win the command fold can control the text (shrink vs extend) depending on the number of the included columns.

In your example:

fold -w 52 file 

and

fold -w 200 file
  • 3
    And, if you want to actually break lines between words like normal text flow would be done, you can use fmt instead of fold... – twalberg Oct 09 '18 at 16:23
3

You can use this command:

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

Where 80 is number of characters you want to have in one line and file is file where you store your text.

.\{80\} - regexp which match exactly 80 characters

&\n - append \n to matched text

mrc02_kr
  • 2,003