Ad Code

Ticker

6/recent/ticker-posts

The Real Command to Wrap Text in Linux

Fold command in Linux

In Linux, the fold command wraps the text with fixed-column width. And it will not consider spaces between words. The result from the fold command will be in fixed-width columns, which resemble a “newspaper” style.

Fold command in Linux

I have explained two examples of wrapping text using the fold command. These are helpful for your project where you need to write a shell script.

Example-1

The following command displays a set of lines with ten characters in each line:

x="aa bb cc d e f g h i j kk ll mm nn" 
echo $x | fold -10

The output of the preceding code snippet is here:

aa bb cc d e f g h i j kk ll m m nn

Example-2

As another example, consider the following code snippet:


x="The quick brown fox jumps over the fat lazy dog. " 
echo $x | fold -10

The output of the preceding code snippet is here:

The quick brown fox jumps over the fat l azy dog.

Post a Comment

0 Comments